重新安装应用程序时推送通知的问题

时间:2018-01-16 11:29:20

标签: ios apple-push-notifications

我在申请中面临一个奇怪的问题。在安装应用程序时在新设备上推送通知工作正常但重新安装我没有收到任何通知的应用程序。它是API的问题还是在终止应用程序时必须做某事?

注册设备的代码:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
        SHARED_MGR.deviceToken = deviceTokenString
        let str = UIDevice.current.identifierForVendor!.uuidString as String
        let characterSetForDeviceID: CharacterSet = CharacterSet( charactersIn: "-" )
        deviceID = ( str as NSString )
            .trimmingCharacters( in: characterSetForDeviceID )
            .replacingOccurrences( of: " ", with: "" ) as String

        SHARED_MGR.DeviceIDStr = deviceID
        createDevice()
    }

请求授权代码:

if( UIDevice.current.systemVersion >= "10.0"){
        if #available(iOS 10.0, *) {
            let center  = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.sound, .alert, .badge], completionHandler: { (granted, error) in
                if granted{
                    UIApplication.shared.registerForRemoteNotifications()

                } else {
                    PHPhotoLibrary.requestAuthorization { (status) in
                        print(status)
                    }
                }
            })
        } else {
            // Fallback on earlier versions
        }


    }
    else {
        let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
        let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
    }

1 个答案:

答案 0 :(得分:0)

请检查您的设备令牌是否在每次新启动时更新到服务器。

如果您使用静态设备令牌进行推送通知,则可能是问题所在。

您没有在新发布时获得推送通知。

因为设备令牌将始终在新安装上更改。