我已經在我的應用程序中完成了本地通知的實現。本地通知被推送,但應用程序無法打開
當手機處於待機狀態(黑屏但未關閉)時,我看到本地通知顯示,我可以滑動,並且有兩個按鈕(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