2017-04-23 16 views
0

我正在开发应用程序,一旦应用程序进入后台(当用户点击iPhone中的主屏幕按钮时)并接收并接听我的电话执行一些操作。当按下home按钮后应用程序处于后台时接收通话事件

下面是我试过的代码,

callCenter = CTCallCenter() 

     self.callCenter!.callEventHandler = {(call: CTCall) -> Void in 
      if (call.callState == CTCallStateConnected) 
      { 
       //do something 
      } 

      else if (call.callState == CTCallStateDisconnected) 
      { 
       //do something 
      } 
     } 
    } 

- 即使应用前景和接收电话的事件被调用,但是当应用程序在后台不起作用。

任何解决方案,使其工作?

注意:我正在将应用程序提交到应用商店(iOS 9及以上版本,swift 2.3),因此打开VoIP功能对我无效,因为它可能会导致拒绝。

+0

你在哪里调用此方法? –

+0

@AlexandreLara ViewDidLoad ... –

+0

如果你的应用程序不在前台,那么你不能通知有关通话事件 – Paulw11

回答

-1

你可以把你的代码在你的AppDelegate.swift下列方法之一:

func applicationWillResignActive(_ application: UIApplication) { 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(_ application: UIApplication) { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 
相关问题