2017-04-23 65 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. 
} 
相關問題