Handling user notifications on iOS 10

后端 未结 3 631
清歌不尽
清歌不尽 2020-12-08 10:32

I have troubles determining when the user taps on a user push notification on iOS 10.

So far, I have been using the -[UIApplicationDelegate application:didRece

3条回答
  •  生来不讨喜
    2020-12-08 10:45

    Swift code for iOS 10:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
    
        if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.currentNotificationCenter()
            center.delegate = self
        }
    
        // ...
    
        return true
    }
    
    @available(iOS 10.0, *)
    func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
    
        print(response.notification.request.content.userInfo)        
    }
    
    @available(iOS 10.0, *)
    func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
    
        print(notification.request.content.userInfo)
    }
    

提交回复
热议问题