小编sin*_*ati的帖子

IOS版本中的本地和推送通知兼容

我开发local NotificationsiOS 10.它工作得很好.但现在我应该如何编码local notifications,push notification如果用户正在使用iOS 9及以上版本.有人可以帮忙吗?

下面是代码 iOS 10

import UIKit
import UserNotifications

@available(iOS 10.0, *)
class ViewController: UIViewController,UNUserNotificationCenterDelegate {
    override func viewDidLoad() {
       super.viewDidLoad()

       if #available(iOS 10.0, *) {
        //Seeking permission of the user to display app notifications
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge], completionHandler: {didAllow,Error in })
        UNUserNotificationCenter.current().delegate = self

       }
   }

   //To display notifications when app is running  inforeground
   func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios uilocalnotification swift

19
推荐指数
2
解决办法
3万
查看次数