我有一個推送通知,當應用程序接收它,我撥打以下訪問推動有效載荷,如果應用程序是無效的
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if userInfo["t"] as! String == "rqst" {
print("type is help request")
if let token = NSUserDefaults.standardUserDefaults().objectForKey("authToken") {
authTokenOfHelper = token as! String
}
let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)
let viewController = storyBoard.instantiateViewControllerWithIdentifier("helperMap")
let navController = UINavigationController.init(rootViewController: viewController)
self.window?.rootViewController = nil
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
helpRequestReceived = true
}
}
這個初始化storyboard.But如果我的應用程序是由系統打死,它是關閉的,設備接收推動,在輕推後沒有發生任何事情。
看來,我必須使用application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
如果應用程序被關閉
但如何在didFinishLaunchingWithOptions訪問用戶信息?
試圖代碼,但如果我打開推什麼也沒有發生。該應用程序無法打開 –
應用程序未打開或didReceiveRemoteNotification未被調用? – technerd
哦不,對不起,應用程序打開,但然後立即崩潰 –