无法注册推送通知(Xcode 7、iOS9) [英] Unable to register for Push Notifications (Xcode 7, iOS9)

查看:25
本文介绍了无法注册推送通知(Xcode 7、iOS9)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的设备升级到 iOS 9,并将我的 Xcode 环境升级到 7.0 (7A220).我的应用通过以下方式注册通知:

I've upgraded my devices to iOS 9 and my Xcode environment to 7.0 (7A220). My app registers for notifications via:

[[UIApplication sharedApplication] registerForRemoteNotifications];

然而,didRegisterForRemoteNotificationWithDeviceToken"或didFailToRegisterForRemoteNotificationsWithError"都没有被调用.此外,我的应用没有出现在设置->通知部分(这告诉我它甚至没有尝试注册远程/推送通知)

However, neither "didRegisterForRemoteNotificationWithDeviceToken" or "didFailToRegisterForRemoteNotificationsWithError" are called. Furthermore, my app does not appear in the Settings->Notifications section (which tells me its not even trying to register for remote/push notifications)

我的 App ID 启用了以下应用服务:

My App ID has the following Application Services enabled:

  • 游戏中心
  • 应用内购买
  • 推送通知

在 Xcode 中,启用了以下功能:

In Xcode, the following capabilities enabled:

  • 推送通知

  • Push Notifications

后台模式(远程通知)

这适用于 iOS 8,使用 Xcode 6 构建的应用程序.此外,当使用 Xcode 7 构建时,它不再适用于 iOS 8 设备.

This worked fine with iOS 8, with app built with Xcode 6. Also, it no longer works with an iOS 8 device when built with Xcode 7.

推荐答案

你使用模拟器吗?

在模拟器中,不支持远程通知.

In a simulator, remote notifications are not supported.

示例代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let pushSettings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Badge ,UIUserNotificationType.Sound ,UIUserNotificationType.Alert], categories: nil)
    application.registerUserNotificationSettings(pushSettings)
    return true
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    application.registerForRemoteNotifications()
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let token=deviceToken.description
    print(token)
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    print(error)
}

Xcode 说:

Error Domain=NSCocoaErrorDomain
Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION"
UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}

这篇关于无法注册推送通知(Xcode 7、iOS9)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆