【问题标题】:I am not receiving fcm push notifications in background on IOS我在 IOS 的后台没有收到 fcm 推送通知
【发布时间】:2017-04-18 18:18:24
【问题描述】:

这是我发送的 json,但我只在 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; }

这是我用来生成上述 json 的 php 代码:

公共函数 sendPushNotification($registration_ids, 数组 $notification, 数组 $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.

【问题讨论】:

  • 是您在应用中启用后台模式
  • 是的,它已启用

标签: ios push-notification


【解决方案1】:

在通知中 =     { alert : ""}

警报应该在那里。在您的 appdelegate 类中还实现了另一件事 backgroundfetch 处理程序方法。

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

} 希望它会起作用。

【讨论】:

    【解决方案2】:

    您应该检查 content_available 标记。这是 Apple 自动转换为 aps->alert(用于后台通知处理)的标准 FCM 有效负载。

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

    仅供参考:FCM guidelines to send notification

    【讨论】:

      【解决方案3】:

      我已经在目标 C 的 app Delegate 中实现了以下方法

      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 {
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-11
        相关资源
        最近更新 更多