[英]IOS 13 APNS didRegisterForRemoteNotificationsWithDeviceToken not called
In capabilities, both Push Notification and Background Mode (Remote notification) is opened.在功能中,推送通知和后台模式(远程通知)均已打开。
I check the value of UIApplication.shared.isRegisteredForRemoteNotifications
in my homepage.我在我的主页中检查了
UIApplication.shared.isRegisteredForRemoteNotifications
的值。 The value is true值为真
I use 4G/3G not wifi (will it influence the APNS call back?)我使用 4G/3G 而不是 wifi(会影响 APNS 回调吗?)
I use Xcode 11.1 (11A1027) and the device is Iphone 11我使用 Xcode 11.1 (11A1027) 并且设备是 Iphone 11
Both didRegisterForRemoteNotificationsWithDeviceToken
and didFailToRegisterForRemoteNotificationsWithError
not called都没有调用
didRegisterForRemoteNotificationsWithDeviceToken
和didFailToRegisterForRemoteNotificationsWithError
my code:我的代码:
fileprivate func registerPushService() { let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in if (granted) { DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() } } }
registerPushService()
is called on didFinishLaunchingWithOptions
.在
didFinishLaunchingWithOptions
上调用registerPushService()
。
============= ==============
Looks like if allowed wifi environment only...看起来如果只允许wifi环境......
Do you perhaps the .provisional option set?您是否设置了.provisional选项?
requestAuthorization(options: [.provisional, .badge, .sound, .alert])
I had the behaviour you describe with this option.我有你用这个选项描述的行为。 When I removed it, the registration went ahead and I got the token.
当我删除它时,注册继续进行,我得到了令牌。 I still haven't figured out how to force it to get a token with this option short of sending local notification first to prompt the user for acceptance of notifications.
我还没有弄清楚如何强制它使用此选项获取令牌,而不是首先发送本地通知以提示用户接受通知。
I would actually move UIApplication.shared.registerForRemoteNotifications()
outside of the requestAuthorization
block.我实际上会将
UIApplication.shared.registerForRemoteNotifications()
移到requestAuthorization
块之外。 The confusing thing about this API is that calling registerForRemoteNotifications()
and receiving a device token does not require user permission - requesting the different notification types (badge, sound, alert) is what actually triggers it.这个 API 令人困惑的是调用
registerForRemoteNotifications()
并接收设备令牌不需要用户许可 - 请求不同的通知类型(徽章、声音、警报)是实际触发它的原因。 Also be sure to try this on a real device - not simulator.还请务必在真实设备上尝试此操作 - 而不是模拟器。 If I recall correctly, remote notifications do not work in simulator and the delegate callbacks will not be called.
如果我没记错的话,远程通知在模拟器中不起作用,并且不会调用委托回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.