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的委托,以告知系统您希望在应用程序运行时显示通知.请参见此处的示例: https://github.com/jerbeers/DemoLocalNotification 总结
以上是内存溢出为你收集整理的swift3 – Local Notificaton无法在模拟器iOS10.0中运行全部内容,希望文章能够帮你解决swift3 – Local Notificaton无法在模拟器iOS10.0中运行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)