- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我遇到了一个奇怪的问题。当我使用以下代码在 didFinishLaunchingWithOptions 中请求远程通知授权时,我能够从我的服务器(Firebase 消息传递)获得推送远程通知,但是当我稍后尝试请求授权时 NOT INSIDE didFinishLaunchingWithOptions 我无法收到任何通知。
我不想在发布时请求授权。例如,我想在用户登录后请求授权。
Apple 文档说:
Always call this method before scheduling any local notifications and before registering with the Apple Push Notification Service. Typically, you call this method at launch time when configuring your app's notification support. However, you may call it at another time in your app's life cycle, providing that you call it before performing any other notification-related tasks.
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
UIApplication.shared.registerForRemoteNotifications()
对这个问题有什么建议/解决方案吗?
应用信息:部署目标:iOS 10.3iOS 设备:装有 iOS 10 的 iPhone 6/装有 iOS 11 的 iPhone 7
最佳答案
我是这样解决的:
在我的 didFinishLaunchingWithOptions
中,我像这样注册远程通知:
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.registerForRemoteNotifications()
然后稍后,例如在用户登录后,我通过调用下面的方法请求授权;
func reqeust() {
// For iOS 10 display notification (sent via APNS)
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in
})
}
关于ios - 在应用程序生命周期的另一个时间请求远程通知授权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46427693/
我正在开发一个使用多个 turtle 的滚动游戏。玩家 turtle 根据按键命令在 Y 轴上移动。当危害和好处在 X 轴上移动时,然后循环并改变 Y 轴位置。我尝试定义一个名为 colliding(
我不明白为什么他们不接受这个作为解决方案,他们说这是一个错误的答案:- #include int main(void) { int val=0; printf("Input:- \n
我正在使用基于表单的身份验证。 我有一个注销链接,如下所示: 以及对应的注销方法: public String logout() { FacesContext.getCurren
在 IIS7 应用程序池中有一个设置 Idle-time out 默认是 20 分钟,其中说: Amount of time(in minutes) a worker process will rem
我是一名优秀的程序员,十分优秀!