- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
isRegisteredForRemoteNotifications
即使我已成功收到设备 token ,也返回false。
在用户安装我的应用程序后,在特定时间点,我会检查 isRegisteredForRemoteNotifications
,如果为 false,我会使用上面的代码请求用户允许通知
func registerUserNotificationSettings() {
let userNotificationTypes: UIUserNotificationType = ([.alert, .badge, .sound])
let settings = UIUserNotificationSettings(types: userNotificationTypes, categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
}
并且在显示对话框并且以太用户推送允许或禁止之后,
didRegister notificationSettings
被调用。我们称
application.registerForRemoteNotifications
里面。哪个调用
didRegisterForRemoteNotificationsWithDeviceToken
然后我们将 token 发送到我们的服务器。
在上述操作之后,如果使用关闭 iOS 设置应用程序的通知,我会显示一个模态警报,要求用户在某个时候将通知设置更改为 ON。我通过这段代码判断显示模态。
func isApproved() -> Bool {
guard let setting = UIApplication.shared.currentUserNotificationSettings else {
return false
}
return setting.types.rawValue > 0
}
如果 isApproved == false,我们显示模态。
在模态框上,我们放置了一个调用以下方法的按钮
func showAppropriateNotificationConfigView() {
if UIApplication.shared.isRegisteredForRemoteNotifications == false {
// case the app has never called registerUserNotificationSettings or registration failed
registerUserNotificationSettings()
} else {
// registerUserNotificationSettings has beeen called and registration succeed
UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
}
}
我们的大多数测试设备返回 true(并且我们确认设备 token 已成功接收)
UIApplication.shared.isRegisteredForRemoteNotifications
但只有我们的一个设备(iPhone7 加 iOS 11.3)返回 false。这样
registerUserNotificationSettings
被调用并且不显示任何内容,而不是通过
将用户发送到设置应用程序UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
我的代码有什么问题,我们该如何解决?
我知道有些方法已被弃用,但我需要临时快速修复它。
最佳答案
我通过更新所有相关的弃用方法解决了这个问题。
关于ios - isRegisteredForRemoteNotifications 即使注册成功也返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50114522/
我正在创建一个 iPhone 应用程序,并希望在应用程序中的某个时间点询问用户推送通知,也就是当他打开开关时。 流程是这样的:启动应用程序->玩游戏->结束游戏->出现带有开关的自定义弹出窗口,询问您
问题 isRegisteredForRemoteNotifications 即使我已成功收到设备 token ,也返回false。 情况 1。注册 在用户安装我的应用程序后,在特定时间点,我会检查 i
在推送通知中,isRegisteredForRemoteNotifications这个方法在模拟器中会返回NO,但在设备中会返回YES。为什么它会有这样的 react ?每次我在设备中运行时需要更改代
我收到了弹出窗口,我已经接受了,我在通知中看到它并且它已打开但是这段代码总是返回否,我似乎无法找出原因 UIApplication *application = [UIApplication shar
下面的方法一直返回相同的值: [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; 每次运行此代码时,结果都是
if UIApplication.sharedApplication().isRegisteredForRemoteNotifications() == true { println("Yes
当我的 iOS 应用程序收到推送通知时,出现了一个奇怪的情况。用户界面保持锁定状态,没有任何效果。当我暂停调试器时,我在我的线程中看到 semaphore_wait_trap。 调试我能看到的代码与两
我是一名优秀的程序员,十分优秀!