我已经在我的应用中完成了本地通知的实施。
当手机处于待机状态(黑屏但未关闭)时,我会看到本地通知显示,我可以滑动,我有两个按钮(接受和拒绝)。
问题:当我点击“接受”时,我可以在调试中看到显示了打印功能(“babam!”),但应用程序保持关闭状态。 Normaly,应用程序应该打开!我留在屏幕上,我需要刷卡解锁并给我密码。也许,因为我必须解锁...但它似乎很奇怪。
您可以查看我如何申报本地通知。但是
似乎是正确的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()
}
答案 0 :(得分:0)
您应该将activationMode值从def SortList(aList):
return sorted(aList, key=lambda el: el[1])
更改为acceptAction.activationMode = UIUserNotificationActivationMode.Background
在你的情况下;
acceptAction.activationMode = UIUserNotificationActivationModeForeground