2017-04-18 2 views
1

Das ist mein JSON, den ich sende, aber ich erhalte nur Benachrichtigungen im Vordergrund in IOS, aber nicht im Hintergrund.Ich erhalte keine fcm Push-Benachrichtigungen im Hintergrund auf IOS

remoteMessage.appData {          colorCode = XXXXX;         description = "XXXXX";     from = XXXXX;     notification =     {         body = "XXXXX";         e=1;     };     notificationName = "XXXXX";     notificationType = XXXXX;     outbid = XXXXX;     paused = XXXXX;     sound = "XXXXX.wav";     suspended = XXXXX; } 

Hier ist der PHP-Code, dass ich die oben json erzeugen bin mit:

public function sendPushNotification ($ registration_ids, array $ Benachrichtigung, array $ message = null) {

 $url = 'https://fcm.googleapis.com/fcm/send'; 
    $notification['notification']['sound'] = $this->_notificationSoundFile; 
    $fields = array(
     'registration_ids' => array($registration_ids), 
     'notification' => $notification['notification'], 
     'data' => $message['message'] 
    ); 
    $headers = array(
     'Authorization:key=' . $this->_fcmKey, 
     'Content-Type: application/json' 
    ); 


    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 

    $result = curl_exec($ch); 


    if ($result === false) 
     throw new Exception('Curl failed ' . curl_error()); 

    curl_close($ch); 
    if ($result) { 
     return json_decode($result, true)['success'] == true ? true : false; 
    } 
} : 

    enter code here 

Expected Output : 

{ 
    aps =     { 
        alert =         { 
            body = "XXXX"; 
            title = ""; 
        };         
        sound = "XXXX.wav"; 
    }; 
    "gcm.message_id" = "XXXX"; 
    "gcm.notification.appointmentId" = XXXX; 
    "gcm.notification.carCode" = XXXX; 
    "gcm.notification.deal_lost" = XXXX; 
    "gcm.notification.dealerCode" = XXXX; 
    "gcm.notification.notificationName" = "XXXX"; 
    "gcm.notification.notificationType" = XXXX; 
    "gcm.notification.outbid" = XXXX; 
    "gcm.notification.paused" = XXXX; 
    "gcm.notification.suspended" = XXXX; 
} 

Help appreciated. 
+0

Sie befinden sich in Ihrer App den Hintergrund-Modus aktivieren –

+0

Ja, es ist aktiviert –

Antwort

1

In Benachrichtigung = {Alarm: ""}

Warnung sollte da sein. Und noch eine Sache backgroundfetch Handler-Methode in Ihrer Klasse appdelegate implementieren.

func Anwendung (_ Anwendung: UIApplication, didReceiveRemoteNotification userinfo: [AnyHashable: Alles], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

} Hoffe, dass es funktionieren wird.

1

Ich habe folgende Methoden in AppDelegate implementiert in Objective C

Dnyaneshwar Wakchaure

- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { 
} 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { 
} 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response 
     withCompletionHandler:(void (^)())completionHandler { 
} 
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
} 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
} 
2

Sie sollten für den Tag content_available überprüfen. Dies ist eine Standard-FCM-Nutzlast, die Apple automatisch in aps-> alert (Für Hintergrundbenachrichtigungsbehandlung) konvertiert.

{ 
    "notification" : { 
     "title": "XXX", 
     "body" : "xxx", 
     "title": "xxx", 
     "content_available": 1 
    }, 
    "data" : { 
     //contain the payload 
    } 
} 

Gerade für mehr Referenz: FCM guidelines to send notification

Verwandte Themen