zoukankan      html  css  js  c++  java
  • 本地通知

    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
  • 相关阅读:
    教你怎么叠T恤
    最动人的情歌《The Power of Love》by Celine.Dion
    使代码简洁的 5 条忠告
    Timeout MessageBox
    内联函数
    局部对象
    const用法(转)
    心情
    内联函数
    局部对象
  • 原文地址:https://www.cnblogs.com/zuidap/p/6274522.html
Copyright © 2011-2022 走看看