gpt4 book ai didi

ios - 滑动本地通知以加载 ui 警报 View

转载 作者:行者123 更新时间:2023-11-30 13:31:14 25 4
gpt4 key购买 nike

我编写了以下通知代码

let notification = UILocalNotification()
notification.fireDate = NSDate(timeIntervalSinceNow: 5)
notification.alertBody = "Do you want to extend your checkout time
notification.alertAction = "to view"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["isExtendCheckOutTime": "true"]

UIApplication.sharedApplication().scheduleLocalNotification(notification)

通知显示得很好,但是当我滑动时,我想加载 UIAlertViewController 并执行一些任务。

我对 swift 完全陌生,想知道我应该在哪里编写代码以获得所需的行为。我在应用程序委托(delegate)中尝试过但没有成功。

最佳答案

如果我没记错的话,只有当你点击actionButton时才有可能。这样你必须添加

func application(application: UIApplication, handleActionWithIdentifier     identifier: String?, forLocalNotification notification:  UILocalNotification, completionHandler: () -> Void) {
if identifier == "CANCEL_ACTION" {
NSNotificationCenter.defaultCenter().postNotificationName("actionCancelPressed", object: nil)
}

completionHandler()
}

到AppDelegate。

并将类别与 UIUserNotificationAction 一起使用。喜欢:

    let cancelAction1 = UIMutableUserNotificationAction()
cancelAction1.identifier = "CANCEL_ACTION"
cancelAction1.title = "cancel"

let cancelAction2 = UIMutableUserNotificationAction()
cancelAction2.identifier = "CANCEL_ACTION"
cancelAction2.title = "cancel"
cancelAction2.activationMode = .Background
cancelAction2.destructive = true
cancelAction2.authenticationRequired = false

let openAction = UIMutableUserNotificationAction()
openAction.identifier = "OPEN_ACTION"
openAction.title = "open"

let actions1 = [cancelAction1, openAction]
let actions2 = [cancelAction2, openAction]

let firstCategory = UIMutableUserNotificationCategory()
firstCategory.identifier = "FIRST_CATEGORY"
firstCategory.setActions(actions1, forContext: .Minimal)

let secondCategory = UIMutableUserNotificationCategory()
secondCategory.identifier = "SECOND_CATEGORY"
secondCategory.setActions(actions2, forContext: .Minimal)

let set: Set<UIUserNotificationCategory> = [firstCategory, secondCategory]

let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories:set)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)

然后

notification.category = "FIRST_CATEGORY"

否则你必须自己捕捉这个 Action 。但我可能是错的!)

关于ios - 滑动本地通知以加载 ui 警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36563868/

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