首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LocalNotification警报干扰

LocalNotification警报干扰
EN

Stack Overflow用户
提问于 2018-01-12 08:08:01
回答 2查看 54关注 0票数 0

我已经在我的应用程序中启用了UserNotifications,除了在一开始(第一次安装)的一个bug之外,一切都运行得很好。本地通知需要询问用户发送通知的权限,并在首次安装时发出警报,用户可以选择他/她的选项("Allow“、"Don't Allow")。问题是这个通知请求在AppDelegate中的"applicationDidFinishLaunchingWithOptions“方法中被调用,并且被另一个警报切断,这是在viewDidLoad中发起的my LocalAuthorization(TouchID)警报。有没有一种方法可以把所有这些警报放在某种队列中,这样它们就会一个接一个地触发,而不是彼此重叠?或者,以某种方式告诉viewDidLoad alert等待AppDelegate alert完成显示?欢迎任何意见。谢谢。

EN

回答 2

Stack Overflow用户

发布于 2018-01-12 08:52:24

将UNUserNotification授权请求从AppDelegate移至viewDidLoad,并在完成块中调用其他告警。

票数 0
EN

Stack Overflow用户

发布于 2018-01-12 17:13:20

扩展ViewController: UNUserNotificationCenterDelegate {

代码语言:javascript
复制
//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()
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48217730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档