这些内容都来自我目前正在开发的一个应用程序,我们称之为样例应用程序
如何从手机托盘中获取这些通知的列表
是的,我确实知道可以使用以下代码获取通知:
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)")
}
但是这段代码的问题在于,我只能获得由我离线创建的通知,而不能获取来自苹果推送通知服务器(APNS)的通知。
所谓离线创建是指,预定的UILocalNotification
,而由于推送通知不是UILocalNotification
,所以我不知道该怎么办。
你可能会问的一些问题
Are these notifications from my app?
- Yes
Am I using the
didReceiveRemoteNotification
on theAppDelegate
?- Yes, but that's different.
Does my remote notifications work/come from APNS
- Yes.
What does my code for registering remote notifications look like?
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 中并不存在所谓的“托盘”,您提到的应该是通知中心。 - Dávid PásztoriOS 10
以下设备的这些通知。 - Zonily JameNSUserDefault
。 - Mathi Arasan