実際に私のアプリで何をしようとしているのですか、私は通知のアラームを設定しています。アプリが強制的に実行されます。通知が来たら、私はそれをタップしています。アプリを開き、開きたい特定のコントローラ(HoroscopeNotificationViewController)を開きません。一方、アプリがバックグラウンドで実行されている場合はアラームを設定した後、通知は、特定のコントローラのオープンと正常に動作します。アプリが終了または終了したときにプッシュ通知をタップした後に特定のコントローラを開く方法
あなたの助けが本当に終了状態または殺された状態に通知のタップ上の特定のビューコントローラを開くには、あなたがアプリで起動オプションのオブジェクトの存在をチェックする必要があり
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let _:UILocalNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: #selector(AppDelegate.showNotification), userInfo: nil, repeats: false)
let firstCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
firstCategory.identifier = "FIRST_CATEGORY"
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("MessagesID : \(userInfo["gcm_message_id"]!)")
print(userInfo)
}
func application(application: UIApplication,
handleActionWithIdentifier identifier:String?,
forLocalNotification notification:UILocalNotification,
completionHandler: (() -> Void))
{
if (identifier == "FIRST_ACTION")
{
NSNotificationCenter.defaultCenter().postNotificationName("actionOnePressed", object: nil)
}
else if (identifier == "SECOND_ACTION")
{
NSNotificationCenter.defaultCenter().postNotificationName("actionTwoPressed", object: nil)
}
completionHandler()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("MessageId: \(userInfo["gcm_message_id"])")
print(userInfo)
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
if #available(iOS 8.2, *) {
print("Function goes here : \(notification.alertTitle)")
} else {
// Fallback on earlier versions
}
if notification.category == "FIRST_CATEGORY" {
sleep(8)
let horoscopeNotificationObj = window?.rootViewController?.storyboard!.instantiateViewControllerWithIdentifier("HoroscopeNotificationViewController") as! HoroscopeNotificationViewController
window?.rootViewController?.presentViewController(horoscopeNotificationObj, animated: true, completion: nil)
}
}
func showNotification() {
NSNotificationCenter.defaultCenter().postNotificationName("modifyListNotification", object: nil)
}
おそらくビューコントローラがまだメモリに読み込まれていません。 View Controllerを表示しようとする前に 'myController.view'を呼び出して、View Controllerを強制的にメモリにロードしてみてください。 – Zhang
Zhang、HoroscopeNotificationViewControllerをロードする場所を教えてください。Appdelegateにありますか?はいの場合、ロードする場所と方法を教えてください。コードの詳細を教えていただければ、私は非常に義務づけられます。 –
あなたはアプリを作った人ではありませんか?あなたはそれがどこにあるかを知るべきです。 Cmd-Shift-Oを押して検索フィールドを表示し、コントローラの名前を入力します。 – Zhang