【发布时间】:2017-08-17 10:04:13
【问题描述】:
所有这些都来自我目前正在开发的一个应用程序,我们称这个应用程序为 SampleApp
如何从我的手机托盘中获取这些通知的列表
是的,我知道我可以通过此代码获取通知
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getPendingNotificationRequests { (requests) in
print("here are the iOS 10 notifs \(requests)")
}
} else {
let requests = (UIApplication.shared.scheduledLocalNotifications ?? [])
print("here are the NON iOS 10 notifs \(requests)")
}
但是这段代码的问题是我只能获得我离线创建的通知,而不是来自Apple Push Notification Server (APNS)的通知p>
我的意思是离线创建,预定UILocalNotifications,由于推送通知不是UILocalNotifications,我不知道该怎么做
您可能会问的一些问题
-
这些通知是来自我的应用吗?
- 是的
-
我是否在
AppDelegate上使用didReceiveRemoteNotification?- 是的,但不一样。
-
我的远程通知是否有效/来自 APNS
- 是的。
-
我用于注册远程通知的代码是什么样的?
if #available(iOS 10.0, *) { let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: authOptions, completionHandler: { (_, _) in }) } else { let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications()
【问题讨论】:
-
你为什么不用
UNUserNotificationCenter.current.getDeliveredNotifications()?此外,iOS 中没有“托盘”之类的东西,您所说的就是通知中心。 -
更新答案并接受自己。
-
@user3589771 我还不能,因为我仍然无法为
iOS 10以下的设备获取这些通知 -
如果没有其他方式获取通知,请使用小于 iOS 10 的
NSUserDefault。
标签: swift notifications system-tray