我有与 APNS 设备令牌相关的问题。在我使用 Xcode 10.2 和 iOS 12.1 之前。此时我曾经在委托方法中获取设备令牌
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Run Code Online (Sandbox Code Playgroud)
我正在像这样注册 APNS,它运行良好。
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
Run Code Online (Sandbox Code Playgroud)
现在,当将 iOS 13 安装到我的 iPhone 设备并使用 Xcode 11 时,不会调用委托方法 didRegisterForRemoteNotificationsWithDeviceToken。无法理解这个问题。我已经对此进行了研究,我知道从委托方法获取令牌有一些变化,但在我的情况下,委托方法甚至没有被调用。同样,它在 iOS 12 上运行良好。