点击通知时如何处理?
adding action 就是在notification中添加新按钮,我不想添加按钮;我想在选择通知时转到特殊 View Controller ,例如 android 中的 builder.setContentIntent
。
我读了 Managing Your App’s Notification Support 但找不到任何东西。
最佳答案
对于 ios 10 或更高版本,有两种处理通知的新方法。
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
This Method called when user tap on notification when app is in foreground.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
This Method called when app is in background.
对于
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
This Method called when app is in background.(You won't able to see notification if app is in foreground but you can get notification in above method)
以及通知权限
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
if !UIApplication.shared.isRegisteredForRemoteNotifications {
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
UIApplication.shared.registerForRemoteNotifications()
}else if #available(iOS 9, *) {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
}
return true
}
关于快速用户通知点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48276560/