2016-10-18 16 views
1

私のアプリがバックグラウンドまたはフォアグラウンドにあるときに私は通知を受け取ることができますが、私のアプリはkillです。私は通知を得ることができません。 私はfcmを使用しています... これは郵便配達員経由で呼び出す私のペイロードです。私のアプリがkillであるときに通知を受け取らない

{ 
"registration_ids": 
    ["...."], 

    "notification":{ 
    "sound":"default", 
    "title":"testNotif", 
    "body":"welcome in the shop Apple owner" 
    } 

} 

これは私のappdelegateです:

import UIKit 
import UserNotifications 

import Firebase 
import FirebaseInstanceID 
import FirebaseMessaging 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

    if #available(iOS 10.0, *) { 
     let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound] 
     UNUserNotificationCenter.current().requestAuthorization(
      options: authOptions, 
      completionHandler: {_,_ in }) 

     UNUserNotificationCenter.current().delegate = self 

     FIRMessaging.messaging().remoteMessageDelegate = self 

    } else { 
     let settings: UIUserNotificationSettings = 
      UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 
     application.registerUserNotificationSettings(settings) 
    } 

    application.registerForRemoteNotifications() 

    FIRApp.configure() 

    return true 
} 

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 


} 

func application(_ application: UIApplication, 
       didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 
    FIRInstanceID.instanceID().setAPNSToken(deviceToken as Data, type: FIRInstanceIDAPNSTokenType.prod) 
} 

func tokenRefreshNotification(notification: NSNotification) { 
    if let refreshedToken = FIRInstanceID.instanceID().token() { 
     print("InstanceID token: \(refreshedToken)") 
    } 

    connectToFcm() 
} 

func connectToFcm() { 
    FIRMessaging.messaging().connect { (error) in 
     if (error != nil) { 
      print("Unable to connect with FCM. \(error)") 
     } else { 
      print("Connected to FCM.") 
     } 

     if let refreshedToken = FIRInstanceID.instanceID().token() { 
      Common.tokenFCM = refreshedToken 
      print("InstanceID token: \(refreshedToken)") 
     } 
    } 
} 

func applicationDidBecomeActive(_ application: UIApplication) { 
    connectToFcm() 
} 

} 


@available(iOS 10, *) 
extension AppDelegate : UNUserNotificationCenterDelegate { 


    private func userNotificationCenter(center: UNUserNotificationCenter, 
           willPresentNotification notification: UNNotification, 
           withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { 
     let userInfo = notification.request.content.userInfo 
     print("<<<<<<< %@", userInfo) 
    } 
} 

extension AppDelegate : FIRMessagingDelegate { 
    func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { 
     print(">>>>> %@", remoteMessage.appData) 

    } 
} 
+0

を確認することができますplzはこのリンクhttp://stackoverflow.com/questions/36929869/push-notification-not-receiving-in-background-iosを読みます/ 36934771#36934771 –

答えて

3

こんにちは、この場合の優先順位に問題があります

{ 

    "registration_ids": 
    ["...."], 
    "priority":"high", 

    "notification":{ 
    "sound":"default", 
    "title":"testNotif", 
    "body":"welcome in the shop Apple owner" 
    } 

} 
+0

素晴らしいそれは働いた –

1

このJSON形式を使用します。設定しない場合は、通常の優先順位であることを意味します。通知がすぐに表示されない可能性があります。優先度をhighに設定すると、すぐに通知を受け取ることを意味します。 iOSバンドル通知がそのように処理する方法が原因である可能性があります。(インスタントメッセージング)、すぐにメッセージを配信するために

試みをし、単に、すぐに通知がお使いのデバイスに表示されるアプリのサーバーとのネットワーク接続を行います

は非常に高い優先順位は何ありません。しかし、もう一つ考慮すべきことは、デバイスの消費電力です。高い優先度は通常よりも多くのバッテリを消費します。詳細情報および詳細については

、あなたはFirebase: Setting the priority of a messageApple Doc

関連する問題