我正在为iOS 10的VoIP应用程序实现PushKit。
我已经在AppDelegate.swift
文件中编写了以下代码:
import PushKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
var window: UIWindow?
private let _pushRegistry = PKPushRegistry(queue: DispatchQueue.main)
//MARK: - App Life Cycle -
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Register for local notifications
NotificationController.registerNotifcationForApplication()
//PushKit
_pushRegistry.delegate = self
var typeSet = Set<PKPushType>()
typeSet.insert(.voIP)
_pushRegistry.desiredPushTypes = typeSet
window!.makeKeyAndVisible()
return true
}
//MARK: - Delegates -
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, forType type: PKPushType) {
DDLogVerbose("PushKit Token: \(credentials.token) length: \(credentials.token.count)")
print("pushRegistry didUpdate credentials")
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
DDLogVerbose("")
print("pushRegistry didInvalidatePushTokenForType")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
DDLogVerbose("Payload: \(payload.dictionaryPayload)")
print("pushRegistry didReceiveIncomingPushWith")
}
}
但是,当我启动该应用程序时,没有任何代表被调用。
它也不能在iOS 9上运行。
我只是通过启用以下Push Notifications
功能来解决此问题:
其实我也已经尝试过了,但是以前没有用。现在,我启用了它,关闭了Xcode 8.2.1,重新打开,清理生成,它开始工作了!
谢谢vin25的回答
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句