我的应用无法生成设备令牌

时间:2016-07-28 13:44:45

标签: swift2 apple-push-notifications

突然间我的应用无法生成设备令牌。 我创建了一个应用程序来接收远程推送通知,应用程序运行良好,但今天我的应用程序不生成设备令牌,我在xcode上运行代码,不生成令牌。没有委托方法调用。 我没有改变任何东西,也没有更多的工作。函数didRegisterForRemoteNotificationsWithDeviceToken不起作用。看:

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

不要打印任何东西

此功能无效:

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

    let types:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]


    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: [newsCategory]))

    return true
}

为什么会出现这个问题?我该如何解决?

1 个答案:

答案 0 :(得分:0)

注册设置后,您还必须在application.registerForRemoteNotifications()中致电application:didFinishLaunchingWithOptions