【问题标题】:Show reminder(alarm) like custom alert and perform user action on that alert in IOS显示提醒(警报),如自定义警报并在 IOS 中对该警报执行用户操作
【发布时间】:2015-08-25 07:53:47
【问题描述】:

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

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    在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/

    【讨论】:

    • 感谢您的回复,我使用了此代码,但是当我单击“完成”操作应用程序时无法打开(确实收到本地通知呼叫)...
    • 感谢您的回答 ....一个问题是有没有其他方式显示提醒(警报),如自定义警报,并在没有本地通知的情况下对该警报执行用户操作。
    • appcoda.com/local-notifications-ios8 看完这个,希望对你有帮助!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    相关资源
    最近更新 更多