当前位置:   iOS > 正文

PushKit没有构思凭据

voip,push,ios,pushkit,go,DevBox,在线流程图,编程,编程问答,程序员,开发者工具,开发工具,json解析,二维码生成,unix时间戳,在线开发工具,前端开发工具,开发人员工具,站长工具

我在这里挣扎了一段时间,可能这是我的错误,但我无法在任何地方找到它,这是一个答案.

我在某些方面实现了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()在代码中调用某个地方.就我而言,我是通过按钮完成的.

请帮我!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/iOS/detail/8923
推荐阅读
相关标签
  

闽ICP备14008679号