gpt4 book ai didi

ios - 显示提醒(警报),例如自定义警报,并在 IOS 中对该警报执行用户操作

转载 作者:行者123 更新时间:2023-11-29 01:43:13 27 4
gpt4 key购买 nike

我想在特定时间向用户显示提醒警报。并对该警报 View 执行操作。我使用本地通知来显示提醒,但当应用程序在后台运行时它会显示角标(Badge)样式的消息。为此,我需要替代解决方案。 提前谢谢你...

最佳答案

在AppDelegate中你应该这样写(这是来 self 的应用程序,只是一个例子,根据你的应用程序使用这段代码)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let completeAction = UIMutableUserNotificationAction()
completeAction.identifier = "COMPLETE_TODO" // the unique identifier for this action
completeAction.title = "Complete" // title for the action button
completeAction.activationMode = .Background // UIUserNotificationActivationMode.Background - don't bring app to foreground
completeAction.authenticationRequired = false // don't require unlocking before performing action
completeAction.destructive = true // display action in red

let remindAction = UIMutableUserNotificationAction()
remindAction.identifier = "REMIND"
remindAction.title = "Remind in 30 minutes"
remindAction.activationMode = .Background
remindAction.destructive = false

let todoCategory = UIMutableUserNotificationCategory() // notification categories allow us to create groups of actions that we can associate with a notification
todoCategory.identifier = "TODO_CATEGORY"
todoCategory.setActions([remindAction, completeAction], forContext: .Default) // UIUserNotificationActionContext.Default (4 actions max)
todoCategory.setActions([completeAction, remindAction], forContext: .Minimal) // UIUserNotificationActionContext.Minimal - for when space is limited (2 actions max)

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: NSSet(array: [todoCategory]))) // we're now providing a set containing our category as an argument
return true
}

有关更多信息,请访问此链接:- http://jamesonquave.com/blog/local-notifications-in-ios-8-with-swift-part-2/

关于ios - 显示提醒(警报),例如自定义警报,并在 IOS 中对该警报执行用户操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32198454/

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