UILocalNotification is deprecated in iOS 10

后端 未结 4 1252
死守一世寂寞
死守一世寂寞 2020-11-28 03:52

It may be a question in advance but I wonder what to use instead of UILocalNotification in iOS 10. I am working on an app which has deployment target iOS 8 so w

4条回答
  •  一生所求
    2020-11-28 04:14

    Apple have done it again, the correct implementation is: AppDelegate.swift

    if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.currentNotificationCenter()
            center.requestAuthorizationWithOptions([.Alert, .Sound]) { (granted, error) in
                // Enable or disable features based on authorization.
            }
        } else {
            // Fallback on earlier versions
        }
    

    and don't forget to add

    import UserNotifications
    

提交回复
热议问题