单击通知时如何处理?
添加操作意味着向通知添加新按钮,我不想添加按钮;builder.setContentIntent
当像在android中选择通知时,我想去特殊的视图控制器。
我阅读了 管理您的应用程序的通知支持 ,但找不到任何内容。
单击通知时如何处理?
添加操作意味着向通知添加新按钮,我不想添加按钮;builder.setContentIntent
当像在android中选择通知时,我想去特殊的视图控制器。
我阅读了 管理您的应用程序的通知支持 ,但找不到任何内容。
对于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)
当应用程序在后台时调用此方法。
对于< 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
}