简体   繁体   English

iOS 11.2.5-didRegisterForRemoteNotificationWithDeviceToken-无响应

[英]iOS 11.2.5 - didRegisterForRemoteNotificationWithDeviceToken - no response

Starting with the OS 11.2.5 my devices weren't able to register a remote notification (eg for silent push purposes. I implemented the registration process within these code lines: 从OS 11.2.5开始,我的设备无法注册远程通知(例如,出于静默推送目的。我在以下代码行中实现了注册过程:

// Ask for notification permission
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {(accepted, error) in
    if !accepted {
        print("Notification access denied.")
    }
}
application.registerForRemoteNotifications()

Additionally, as you already know, you need to implement the following two methods, in order to register a remote notification at Apple: 此外,您已经知道,您需要实现以下两种方法,才能在Apple上注册远程通知:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    let tokenParts = deviceToken.map { data -> String in
        return String(format: "%02.2hhx", data)
    }
    let token = tokenParts.joined()
    // Get my token here and do additionally stuff
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    // Handling error for registering here
}

So my question would be the following: This implementation has been working until Apple OS Update 11.2.4: The didRegisterForRemoteNotificationsWithDeviceToken was successfully called after registering a device and in case of an error the other method didFailToRegisterForRemoteNotificationsWithError was called -> everything perfect! 所以我的问题是:该实现一直有效,直到Apple OS Update 11.2.4:注册设备后成功调用了didRegisterForRemoteNotificationsWithDeviceToken ,并且在发生错误的情况下,另一个方法didFailToRegisterForRemoteNotificationsWithError被调用了->一切完美!

But starting with OS 11.2.5 I got no response from Apple anymore. 但是从OS 11.2.5开始,我再也没有收到苹果的回应。 I spent a lot of time investigating this issue. 我花了很多时间调查这个问题。 After Apple released OS 11.2.6 it worked like charm again -> I'm totally confused. 苹果发布OS 11.2.6之后,它再次像魅力一样工作->我完全感到困惑。

Does anybody know, if this is a known issue in OS 11.2.5? 有人知道,如果这是OS 11.2.5中的已知问题? - Thanks Alex -谢谢亚历克斯

I guess the problem caused at registering for remote notification, try below code please: 我猜是在注册远程通知时引起的问题,请尝试以下代码:

// Ask for notification permission
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {(accepted, error) in
    if accepted {
        DispatchQueue.main.async {
             UIApplication.shared.registerForRemoteNotifications()
        }
    }else{
        print("Notification access denied.")
    }
}
use updated methods.


// Push Notifications
    func registerForPushnotifications(application: UIApplication)
    {
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
                guard granted else{ return }
                self.getNotificationSetting()
            }
        }
        else
        {
            // Fallback on earlier versions
            let notificationSettings = UIUserNotificationSettings(
                types: [.badge, .sound, .alert], categories: nil)
            application.registerUserNotificationSettings(notificationSettings)
        }
    }
    // Push Notification settings
    func getNotificationSetting()
    {
        if #available(iOS 10.0, *)
        {
            UNUserNotificationCenter.current().getNotificationSettings { (settings) in
                guard settings.authorizationStatus == .authorized else {return}
                DispatchQueue.main.async {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        }
    }
    // Push Notifications Delegates

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
    {
        let tokenParts = deviceToken.map { data -> String in
            return String(format: "%02.2hhx", data)
        }
    }

    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
    {
        print("Failed to register for remote Notifications due to: \(error.localizedDescription)")
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 11.2.5上不会旋转Textarea插入符号 - Textarea caret is not rotated on iOS 11.2.5 Ubuntu 14.04 + IOS 11.2.5未处理的锁定错误(-3) - Ubuntu 14.04 + IOS 11.2.5 Unhandled Lockdown error (-3) (iOS 11.2.5)具有Apple Mobile Web应用功能的中断 <input type=“file”> 解决方法? - (iOS 11.2.5) apple-mobile-web-app-capable breaks <input type=“file”> workaround? Instagram iPhone Hooks iOS 11.2.5 instagram 29,供稿未打开文件,但相机胶卷 - Instagram iPhone Hooks iOS 11.2.5 instagram 29, feed not opening the file, but the camera roll 您的应用程序在连接到IPv6网络的运行iOS 11.2.5的iPad或iPhone上崩溃,但为什么? - Your app crashed on iPad or iPhone running iOS 11.2.5 connected to an IPv6 network but Why? 准则2.1-性能在我们的审查过程中,您的应用程序在运行iOS 11.2.5且连接到IPv6网络的iPad或iPhone上崩溃了 - Guideline 2.1 - Performance Your app crashed on iPad or iPhone running iOS 11.2.5 connected to an IPv6 network during our review ARkit统一项目,视频播放停止。 iOS 11.2.5,错误:Domain = com.apple.arkit.error代码= 102“必需的传感器失败。” - ARkit unity project, video playback stops. iOS 11.2.5 with error: Domain=com.apple.arkit.error Code=102 “Required sensor failed.” 在iPad Pro 11.2.5 App中崩溃 - In iPad pro 11.2.5 App get crashed iOS URL响应布尔 - iOS url response bool iOS NSURLSessionUploadTask响应数据 - iOS NSURLSessionUploadTask response data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM