iOS 9 推送通知 dyld`dyld_fatal_error :

标签 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

最佳答案

尝试使用以下行将 token 替换为 String 转换:

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

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

关于iOS 9 推送通知 dyld`dyld_fatal_error :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47199914/

相关文章:

ios - 在 UIButton 中创建三角形

ios - 将 FirebaseUI-IOS 与自定义 UICollectionViewCell 一起使用时出错

ios - 重命名项目后找不到共享内部框架

swift - 检查网页是否正常运行的最有效方法?

ios - RegisterUserNotificationSettings 干扰网络请求

javascript - Chrome推送通知-点击后如何打开URL地址?

ios - 本地化 siri 捐赠的快捷方式

ios - 使用 Core Data 时,您是否保留非托管对象类及其托管对象版本

swift - 在 Swift 中生成跨两个没有关系的实体的获取请求

Flutter 本地通知每 72 小时显示一次通知