swift - 为什么我收到设备未注册 apns 错误?我有开发环境的有效证书

标签 swift apple-push-notifications

为什么我收到设备未注册 apns 错误?我没有收到设备 ID 我尝试按照以下方式获取 deviceid

       func application(application: UIApplication, 
          didFinishLaunchingWithOptions 
    launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    var types: UIUserNotificationType = UIUserNotificationType.Badge |
        UIUserNotificationType.Alert |
        UIUserNotificationType.Sound

    var settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)

    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()

    return true
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    var characterSet: NSCharacterSet = NSCharacterSet(charactersInString: "<>")

    var deviceTokenString: String = (deviceToken.description as NSString)
        .stringByTrimmingCharactersInSet(characterSet)
        .stringByReplacingOccurrencesOfString( " ", withString: "") as String

    println(deviceTokenString)

}

是因为苹果错误吗?

最佳答案

确保您在 xcode 中添加了推送通知权利,并且应用程序 ID 已通过推送通知注册。 查看屏幕截图enter image description here

关于swift - 为什么我收到设备未注册 apns 错误?我有开发环境的有效证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43323982/

相关文章:

iphone - 允许的 APNS 持久连接数是多少?

ios - 实现支持返回搜索结果的导航

ios - 使用给定的坐标和以米为单位的距离计算新坐标

ios - PushSharp Push 在停止之前不会处理队列

xcode - 如何使用 Storyboard 在 AppDelegate 中使用自定义 Navigationcontroller

iOS - 推送内容

ios - Swift 中的 AudioToolBox - 声音在模拟器中有效,但在我的 iPad 上无效

swift - 即使在使用 .contentVerticalAlignment 为 .center 后,文本字段中的文本也会显示在文本字段的底部。这是 iPhone 特有的

swift - Aftersave Cloud Function for Parse 会增加另一个数据表中的值?

ios - Entitlements.plist 与 Appname.Entitlements