iOS 9推送通知dyld`dyld_fatal_error:

时间:2017-11-09 10:49:41

标签: ios swift push-notification apple-push-notifications

我在iOS设备上运行时收到推送通知错误。 iOS版本是9.在Xcode中,我的部署目标也设置为9.0以下是我的AppDelegate代码,我也附上了错误的快照。亲自帮助

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
    UIApplication.shared.registerForRemoteNotifications()
    return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    var token = ""
    for i in 0..<deviceToken.count {
        token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
    }
    print("Registration succeeded! Token: ", token)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("APNs registration failed: \(error)")
}
func showAlertAppDelegate(title: String,message : String,buttonTitle: String,window: UIWindow){
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.default, handler: nil))
    window.rootViewController?.present(alert, animated: false, completion: nil)
}

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用以下行替换tokenString转换:

let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})

我建议您使用Exception断点来获取有关错误的更多信息。以下是a link如何使用它。