我遇到与APNS设备令牌相关的问题。在我使用Xcode10.2和iOS 12.1之前。此时,我通常在委托方法中获取设备令牌
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken我正在注册像这样的APNS,它工作得很好。
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];现在,当使用Xcode11将Xcode13安装到我的iPhone设备上时,委托方法不会被调用。无法理解此问题。我已经对此做了研究,我知道从委托方法获取token有一些变化,但在我的例子中,委托方法甚至没有被调用。同样,它在iOS 12上工作得很好。
发布于 2019-10-28 23:43:27
只需重新启动iPhone即可。就这么简单,在90%的情况下,它会解决你的问题。
发布于 2020-02-16 10:07:46
登录https://appleid.apple.com/,然后打开url "https://developer.apple.com/account/ios/identifier/bundle“或"https://developer.apple.com/account/resources/certificates/list”。
首先,创建两个新证书:(1)Apple Development Sign您的iOS、macOS、tvOS和watchOS应用程序的开发版本。在Xcode 11或更高版本中使用。(2)Apple distribution对您的应用程序进行签名,以便提交到App Store或进行临时分发。用于Xcode 11或更高版本。
然后通过url "https://developer.apple.com/account/resources/identifiers/list“找到菜单”标识符“。编辑您的应用程序的标识符,确保开发SSL证书和生产SSL证书添加到推送通知。
下一步,打开菜单“档案”通过网址"https://developer.apple.com/account/resources/profiles/list“。确保证书类型为将在Xcode11或更高版本中使用的DistributionFor,并保存
最后,将配置配置文件和创建的CA证书文件下载到您的MAC,它们将通过双击文件分别添加到XCode和密钥链应用程序中。
更重要的是,记得重启你的手机,并确保你已经正确设置了远程通知。
发布于 2019-12-24 22:11:18
我也面临着同样的问题。我尝试了很多场景。在完成以下步骤后,我获得了成功:
registerForRemoteNotifications方法。在我的例子中,我得到了一个设备令牌,但响应有延迟(我认为是因为在后台线程中注册了远程通知)。但是在主线程中移动[[UIApplication sharedApplication] registerForRemoteNotifications]之后,一切工作正常。
下面是我的代码:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = delegate;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
[self callCompletion:TRUE completion:completion];
});
}
}];希望这能有所帮助。
https://stackoverflow.com/questions/58264338
复制相似问题