本地通知

import UserNotifications

func regisNot(){

        

        if #available(iOS 10.0, *) {

            UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) { (success, error) in

                if success {

                    print("success")

                } else {

                    print("error")

                }

            }

        } else {

            // Fallback on earlier versions

        }

        

        

        // 1

        if #available(iOS 10.0, *) {

            let content = UNMutableNotificationContent()

            content.title = "Notification Tutorial"

            content.subtitle = "from ioscreator.com"

            content.body = " Notification triggered"

            

            // 2

            let imageName = "Icon123"

            guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return }

            

            let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)

            

            content.attachments = [attachment]

            

            // 3

            let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)

            let request = UNNotificationRequest(identifier: "notification.id.01", content: content, trigger: trigger)

            

            // 4

            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

        } else {

            // Fallback on earlier versions

        }

        

        

        

        

        

        

    }

    

群号:186052819
原文地址:https://www.cnblogs.com/zuidap/p/6274522.html