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

My app cannot generate device token

我的应用程序突然无法生成设备令牌。 我创建了一个应用程序来接收远程推送通知,该应用程序运行良好,但今天我的应用程序不生成设备令牌,我 运行 在 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
}

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

您还必须在注册设置后在 application:didFinishLaunchingWithOptions 中调用 application.registerForRemoteNotifications()