如何在ios手机phonegap编程中处理拨出和拨入电话的应用程序?

时间:2015-06-12 10:19:33

标签: javascript ios objective-c cordova phonegap-plugins

如果有任何拨出电话和来电,任何人都可以建议我如何处理iOS手机中的应用程序。实际上我是基于电话间隙的应用程序的新手

目前我正在开发一个应用程序来跟踪背景中的位置。如果出现任何来电或去电,我需要停止我的应用后台位置跟踪(来电/去电)并在通话结束后开始位置跟踪。

我已经提到过这个链接: How detect incoming and outgoing call end state? iphone

   [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];

1 个答案:

答案 0 :(得分:1)

添加核心电话框架及其委托方法解决了我的要求。

   //Initialize the plugin
  - (void)pluginInitialize
   {
   self.callCenter = [[CTCallCenter alloc] init];
   [self handleCall];

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];
    }


 //handle calls
 -(void)handleCall
   {
    self.callCenter.callEventHandler = ^(CTCall *call){

    if ([call.callState isEqualToString: CTCallStateConnected])
    {
        NSLog(@"call CTCallStateConnected");//Background task stopped
    }
    else if ([call.callState isEqualToString: CTCallStateDialing])
    {
        NSLog(@"call CTCallStateDialing");
    }
    else if ([call.callState isEqualToString: CTCallStateDisconnected])
    {
        NSLog(@"call CTCallStateDisconnected");//Background task started
    }
    else if ([call.callState isEqualToString: CTCallStateIncoming])
    {
        NSLog(@"call CTCallStateIncoming");
    }
    else  {
        NSLog(@"call NO");
    }
  };
 }