点击通知后如何处理?
添加动作意味着添加新的通知按钮,我不想添加按钮;当我在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)
当应用程序位于前台时,用户点击通知时会调用此方法。
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
当app在后台时调用此方法。
对于<ios 10
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
此应用程序在后台调用此方法。(如果应用程序位于前台,您将无法看到通知,但您可以通过上述方法获得通知)
并且用于通知许可
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
}