我在我的应用程序中启用了 UserNotifications,除了一开始的错误(首次安装)之外,一切都很好。本地通知需要询问用户发送通知的权限,它在首次安装时作为警报出现,用户可以选择他/她的选项(“允许”、“不允许”)。问题是这个通知请求是在 AppDelegate 的“applicationDidFinishLaunchingWithOptions”方法中调用的,它被另一个警报切断,这是我在 viewDidLoad 中启动的 LocalAuthorization(TouchID) 警报。有没有办法将所有这些警报放在某种队列中,这样它们就会一个接一个地被触发而不是相互触发?或者,以某种方式告诉 viewDidLoad 警报等待 AppDelegate 警报完成显示?欢迎任何意见。谢谢。
问问题
55 次
2 回答
0
扩展视图控制器: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()
}
}
于 2018-01-12T09:13:19.613 回答
0
将 UNUserNotification 授权请求从 AppDelegate 移动到 viewDidLoad 并在完成块中调用其他警报。
于 2018-01-12T00:52:23.923 回答