【发布时间】:2015-08-25 07:53:47
【问题描述】:
我想在特定时间向用户显示提醒警报。并对该警报视图执行操作。我使用本地通知来显示提醒,但当应用程序在后台运行时它会显示徽章样式消息。我需要替代解决方案。 提前谢谢你...
【问题讨论】:
我想在特定时间向用户显示提醒警报。并对该警报视图执行操作。我使用本地通知来显示提醒,但当应用程序在后台运行时它会显示徽章样式消息。我需要替代解决方案。 提前谢谢你...
【问题讨论】:
在AppDelegate中你应该这样写(这是我的应用,只是一个例子,根据你的应用使用这个代码)
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/
【讨论】: