赞
踩
我在这里挣扎了一段时间,可能这是我的错误,但我无法在任何地方找到它,这是一个答案.
我在某些方面实现了PushKit,但没有一个是有效的.
我已经添加了正确的后台模式,以正确的方式实现了回调,didUpdatePushCredentials
正在被正常调用...
但是,credentials: PKPushCredentials!
变量,给我一个错误指针......它不是空的......不是零...没有任何东西......它根本就没有值......它被分配了垃圾......因为这个原因..我收到了EXC_BREAKPOINT ..
我试过3种不同的设备......行为相同......
我已经创建了VoIP推送证书......
我以不同的方式做到了:
通过在didRegisterForRemotePushNotification之后创建void Push Registry对象
通过创建推送注册表而无需注册远程推送通知...
通过使用主队列,全局队列和自定义队列创建注册表.
总是一样......
这是代码:
extension AppDelegate : PKPushRegistryDelegate { func registerForVoipPush() { self.registry = PKPushRegistry(queue:nil) if self.registry != nil { self.registry!.delegate = self self.registry!.desiredPushTypes = Set(arrayLiteral: PKPushTypeVoIP) } //let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories:nil) //UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) } func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) { //print out the VoIP token. We will use this to test the nofications. NSLog("voip token: \(credentials.token)") if credentials != nil { let username = NSUserDefaults.standardUserDefaults().objectForKey("username") as? String if username != nil { ServerDefinitions.subscribeForPush(username!, token: NSString(data: credentials.token, encoding: NSUTF8StringEncoding) as! String, callback: { (retMsg) -> Void in print(retMsg) }) } } } func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) { let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary let message = payloadDict?["alert"] //present a local notifcation to visually see when we are recieving a VoIP Notification if UIApplication.sharedApplication().applicationState == UIApplicationState.Background { let localNotification = UILocalNotification(); localNotification.alertBody = message localNotification.applicationIconBadgeNumber = 1; localNotification.soundName = UILocalNotificationDefaultSoundName; UIApplication.sharedApplication().presentLocalNotificationNow(localNotification); } else { dispatch_async(dispatch_get_main_queue(), { () -> Void in print("Incoming Call") }) } NSLog("incoming voip notfication: \(payload.dictionaryPayload)") } func pushRegistry(registry: PKPushRegistry!, didInvalidatePushTokenForType type: String!) { NSLog("token invalidated") }
}
编辑:
请注意,上面的代码是AppDelegate的扩展,仅用于分隔代码,因此它更具可读性.
我还在var registry : PKPushRegistry?
AppDelegate上添加了.为了使其工作,您必须registerForVoipPush()
在代码中调用某个地方.就我而言,我是通过按钮完成的.
请帮我!
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。