我已经在我的应用程序中完成了本地通知的实现。本地通知被推送,但应用程序无法打开
当手机处于待机状态(黑屏但未关闭)时,我看到本地通知显示,我可以滑动,并且有两个按钮(Accept & Decline)。
问题:当我点击接受,我可以看到调试该功能触发与打印(“巴巴!”)显示,但应用程序保持关闭。通常,应用程序应该打开!我留在屏幕上,我需要刷卡解锁并给出我的密码。也许,因为我必须解锁......但似乎很奇怪。
你可以检查我如何声明我的本地通知。但它似乎正确与
declineAction.authenticationRequired = false
所以任何帮助将不胜感激!
let acceptAction = UIMutableUserNotificationAction()
acceptAction.identifier = "Accept"
acceptAction.title = "Accept"
acceptAction.activationMode = UIUserNotificationActivationMode.Background
acceptAction.destructive = false
acceptAction.authenticationRequired = false
let declineAction = UIMutableUserNotificationAction()
declineAction.identifier = "Decline"
declineAction.title = "Decline"
declineAction.activationMode = UIUserNotificationActivationMode.Background
declineAction.destructive = false
declineAction.authenticationRequired = false
let category = UIMutableUserNotificationCategory()
category.identifier = "invite"
category.setActions([acceptAction, declineAction], forContext: UIUserNotificationActionContext.Default)
let categories = NSSet(array: [category])
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories as? Set<UIUserNotificationCategory>)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
正下方时,我选择哪个触发FUNC “接受”
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) {
NSLog("Handle identifier : \(identifier)")
// Must be called when finished
if identifier == "Accept"{
print("babam!!!")
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var destinationController = storyboard.instantiateViewControllerWithIdentifier("gosondage1") as? Sondage
var frontNavigationController = UINavigationController(rootViewController: destinationController!)
var rearViewController = storyboard.instantiateViewControllerWithIdentifier("MenuController") as? MenuController
var mainRevealController = SWRevealViewController()
mainRevealController.rearViewController = rearViewController
mainRevealController.frontViewController = frontNavigationController
self.window!.rootViewController = mainRevealController
self.window?.makeKeyAndVisible()
}
completionHandler()
}
是的,谢谢它的工作。在这种情况下,我们是否需要使用.background而不是前景? – user2971617
我不知道这取决于你的应用需求。例如,当您收到新消息或电子邮件时,邮件应用程序会发送推送通知或WhatsApp,如果您希望可以通过阅读按钮(.foreground)打开应用程序,或者您可以使用取消按钮(.background)忽略消息,因此取决于您的需求。 – emresancaktar