快速用户通知点击

标签 swift select click usernotifications

点击通知时如何处理?

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/

相关文章:

vb.net - 返回数据集中表的前 5 条记录

sql - 计算sql server中的平均评分

hyperlink - 单击具有已知文本特定部分的链接 - watir webdriver

javascript - JS 变量 onclick 增量

xcode - WebView 具有多个按钮以在同一页面中浏览文件

ios - 在 UITableView 中自定义标题

PHP MySQL - 从不同的表中选择具有 where-clause 语句的成员

Javascript 单击功能仅适用于第一个元素

swift - 如何从苹果指南中理解 "add new instance methods by extentions"?

ios - 向按钮添加目标时,为什么目标操作必须是 objc func?