我已经在我的应用程序中启用了UserNotifications,除了在一开始(第一次安装)的一个bug之外,一切都运行得很好。本地通知需要询问用户发送通知的权限,并在首次安装时发出警报,用户可以选择他/她的选项("Allow“、"Don't Allow")。问题是这个通知请求在AppDelegate中的"applicationDidFinishLaunchingWithOptions“方法中被调用,并且被另一个警报切断,这是在viewDidLoad中发起的my LocalAuthorization(TouchID)警报。有没有一种方法可以把所有这些警报放在某种队列中,这样它们就会一个接一个地触发,而不是彼此重叠?或者,以某种方式告诉viewDidLoad alert等待AppDelegate alert完成显示?欢迎任何意见。谢谢。
发布于 2018-01-12 08:52:24
将UNUserNotification授权请求从AppDelegate移至viewDidLoad,并在完成块中调用其他告警。
发布于 2018-01-12 17:13:20
扩展ViewController: UNUserNotificationCenterDelegate {
//for displaying notification when app is in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//If you don't want to show notification when app is open, do something here else and make a return here.
//Even you you don't implement this delegate method, you will not see the notification on the specified controller. So, you have to implement this delegate and make sure the below line execute. i.e. completionHandler.
completionHandler([.alert, .badge, .sound])
}
// For handling tap and user actions
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
switch response.actionIdentifier {
case "action1":
print("Action First Tapped")//here you can your alert
case "action2":
print("Action Second Tapped")//here you can your alert
default:
break
}
completionHandler()
}}
https://stackoverflow.com/questions/48217730
复制相似问题