2
私はアプリはプッシュ通知を経由して開いているかどうかを検出するために、別のスタックオーバーフローのポストからこのソリューションを取った:iOSでプッシュ通知でアプリが開かれていないかどうかを検出しますか?
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
print("Push notification received: \(data)")
if #available(iOS 9, *) {
if let type = data["type"] as? String, type == "status" {
// IF the wakeTime is less than 1/10 of a second, then we got here by tapping a notification
if application.applicationState != UIApplicationState.background && NSDate().timeIntervalSince(wakeTime as Date) < 0.1 {
// User Tap on notification Started the App
sendPushStatistic()
}
else {
// DO stuff here if you ONLY want it to happen when the push arrives
}
}
else {
}
}
}
今私はアプリはクリックせずに(コールドスタートとバックグラウンドから)開かれたかどうかを確認する方法を疑問に思いますプッシュ通知ではなく、アプリアイコンまたは実行中のアプリビューから
"applicationdidfinishlauching"メソッドを確認できます。ユーザーがアプリアイコンをクリックしたときにアプリが起動されるときに呼び出されます。 – Pawan
プッシュで開くと呼び出されませんか?ありがとうございました! –
アプリケーションがすでにバックグラウンドで実行されている場合はnoです。 – Pawan