使用PushKit / voip将应用程序启动到前台

时间:2015-11-11 23:32:26

标签: ios

我的应用程序已注册为后台模式:IP语音,后台提取和远程通知。

我使用下面的代码成功收到了voip推送通知,但我无法启动应用程序来接听电话。收到voipPush后,如何在没有任何用户互动的情况下启动应用程序?

import UIKit
import PushKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {

var voipRegistry:PKPushRegistry!
var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    voipRegistry = PKPushRegistry(queue: dispatch_get_main_queue())
    voipRegistry.delegate = self
    voipRegistry.desiredPushTypes = Set([PKPushTypeVoIP])
    print("VOIP Push registered")

    return true
}

func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
    let voipToken: String! = credentials.token.description
    print("\n\n##### PushKit credential: \n\n", voipToken)
}

func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
    let data = payload.dictionaryPayload
    print("\n\n##### Received PushKit Data: \n\n", data)
    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let videocallViewController = storyboard.instantiateViewControllerWithIdentifier("videocallViewController")
    window!.rootViewController = videocallViewController

}
}

0 个答案:

没有答案
相关问题