gpt4 book ai didi

swift3 - 本地通知在模拟器 iOS 10.0 中不起作用

转载 作者:行者123 更新时间:2023-12-04 22:57:07 25 4
gpt4 key购买 nike

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
askForPermission()
}

@IBAction func addLocalNotification(_ sender: AnyObject) {

addLocalNotification()
}

func addLocalNotification() {

let content = UNMutableNotificationContent()
content.title = "iOS10.0"
content.body = "Hello Buddy"
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
let request = UNNotificationRequest.init(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error) in
print(error)
}
print("should have been added")
}

func askForPermission() {

UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]) { (granted, error) in

}
}

最佳答案

你必须实现一个 UNUserNotificationCenter 的委托(delegate)来告诉系统你想在应用程序运行时显示通知。在此处查看示例:https://github.com/jerbeers/DemoLocalNotification

关于swift3 - 本地通知在模拟器 iOS 10.0 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40237015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com