5

私のプロジェクトでは、Firebase NotificationsをAPNサービスとして使用していますが、Firebaseコンソールを使用してデバイスに通知を送信していましたが、フォアグラウンドで表示されます。アプリがバックグラウンドにあるとき、またはデバイスがロック画面にあるときは、デバイスに通知はありません。しかし、コンソール出力は、私がアプリケーションを開いたときに、applicationReceivedRemoteMessageメソッドから最終的に到着します。applicationReceivedRemoteMessageはフォアグラウンドでのみ実行されます

func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { 

     print("%@", remoteMessage.appData) 
     print("QQQQQ") 
    } 

出力例:

%@ [AnyHashable("notification"): { 
    body = Hi; 
    e = 1; 
}, AnyHashable("from"): 492525072004, AnyHashable("collapse_key"): org.myApp] 
QQQQQ 
+0

[アプリ外でAPNを受信しない]の可能な複製(http://stackoverflow.com/questions/40295475/not-receiving-apns-when-out-of-app) – Chris

+0

私にあなたを参照した質問答えがなく、言い方が異なります。 –

答えて

0

iOSとデータメッセージに問題があります。それは、FCMは、メッセージを格納し、アプリが でフォアグラウンドで、FCMの接続を確立している場合にのみ、それを実現しhere

iOSの上で

と述べています。

したがって、回避策が必要です。

{ 
    "to" : "/topics/yourTopicName", 
    "notification" : { 
    "priority" : "Normal", 
    "body" : "Notification Body like: Hey! There something new in the app!", 
    "title" : "Your App Title (for example)", 
    "sound" : "Default", 
    "icon" : "thisIsOptional" 
    } 
} 
:鉱山に似た何か:

は2つのプッシュ通知の送信:アプリは、このコードを使用してバックグラウンドで動作している間、

1)通常、ユーザーの携帯電話/を覚ますためには、開始します

2)ユーザーがアプリを開いたときにトリガーされるデータ通知

012あなたが作成するためにそれを使用することができますので、私も(ローカル通知を作成する)アプリ内通知をトリガするために、このコードを残して

- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { 
// Print full message 
NSLog(@"%@", remoteMessage.appData); 
// 
//*** ABOUT remoteMessage.appData ***// 
// remoteMessage.appData is a Key:Value dictionary 
// (data you sent with second/data notification) 
// so it's up to you what will it be and how will the 
// app respond when it comes to foreground. 
} 

:あなたのデータを扱う- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage法の下で

と、そう、沈黙のバナーは、多分、ユーザーが再び通知されてアプリがフォアグラウンドに来る場合でも:

NSDictionary *userInfo = remoteMessage.appData;  
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
localNotification.userInfo = userInfo; 
localNotification.soundName = UILocalNotificationDefaultSoundName; 
localNotification.alertBody = userInfo[@"yourBodyKey"]; 
localNotification.alertTitle = userInfo[@"yourTitleKey"]; 
localNotification.fireDate = [NSDate date]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

それは同じ通知第二のアプリがフォアグラウンドに来るがトリガされます。

関連する問題