如何知道我的应用程序已在目标c中进行了调用? [英] How to know call has been made from my application in objective c?

查看:57
本文介绍了如何知道我的应用程序已在目标c中进行了调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS的新手,所以当我出错时请原谅我.我想从我的应用程序中打电话给我,我为此写了这些代码:-

I am new to iOS so pardon me when i make mistake. i want call a person from my application and i wrote these code for that :-

- (IBAction)onClickCallIcon:(id)sender {
    NSString *phoneNumber =_lblLeadMobileNumber.text;
    NSURL *phoneUrl = [NSURL URLWithString:[@"telprompt://" stringByAppendingString:phoneNumber]];
    NSURL *phoneFallbackUrl = [NSURL URLWithString:[@"tel://" stringByAppendingString:phoneNumber]];

    if ([UIApplication.sharedApplication canOpenURL:phoneUrl]){
        [UIApplication.sharedApplication openURL:phoneUrl];
    } else if ([UIApplication.sharedApplication canOpenURL:phoneFallbackUrl]){
        [UIApplication.sharedApplication openURL:phoneFallbackUrl];
    } 
}

我想知道,是否已拨打电话?如果可能的话,通话时间有多长.如何实现呢?

and i want to know, Is call has been made or not? if possible how much length of call. how can achieve it?

推荐答案

@ Anbu.karthik&@Rocky帮助我.我用allKit/CXCallObserver观察了呼叫,这是我问题第二部分的答案,从那部分中我也得到了第一部分的答案,即呼叫是否接通.通过使用以下代码:-

@Anbu.karthik & @Rocky for helping me. i used allKit/CXCallObserver to observe the call which is the answer of second part of my question and from that part i also get answer of first i.e call is connected or not. by using following code:-

在查看负载中:

CXCallObserver *callObserver = [[CXCallObserver alloc] init];
        [callObserver setDelegate:self queue:nil];
        self.callObserver = callObserver;

和方法:

- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {


    if (call.isOutgoing == YES && call.hasConnected == NO) {
        NSLog(@"CXCallState : Dialing");
    }

    if (call.isOutgoing == NO  && call.hasConnected == NO && call.hasEnded == NO && call != nil) {
        NSLog(@"CXCallState : Incoming");
    }

    if (call.hasConnected == YES && call.hasEnded == NO) {
        NSLog(@"CXCallState : Connected");
        startDate = [NSDate date];
    }
    if (call.hasConnected == YES && call.hasEnded == YES){
        NSLog(@"********** voice call disconnected **********/n");
        endDate = [NSDate date];
        NSDateComponents *components = [[NSCalendar currentCalendar] components: NSCalendarUnitSecond
                                                                       fromDate: startDate toDate: endDate options: 0];
        NSInteger second = [components second];
        NSLog(@"call duration == %ld",(long)second);
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
        [formatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
        NSString *startDateFormatted = [formatter stringFromDate: startDate];
        NSString *endDateFormatted = [formatter stringFromDate: endDate];
        NSMutableDictionary *Dict = [[NSMutableDictionary alloc] init];
        [Dict setValue:startDateFormatted forKey:@"startDate"];
        [Dict setValue:endDateFormatted forKey:@"endDate"];
        [Dict setValue:[NSString stringWithFormat:@"%ld", (long)second] forKey:@"interval"];
        [currentShowingData updateCommunications:Dict];
    }

这些给了我我想要的一切.再次感谢谁帮助了我.

these give me all what i wanted. thanks again who helped me.

这篇关于如何知道我的应用程序已在目标c中进行了调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆