【问题标题】:Send Notification to ios app bundle id using FCM使用 FCM 向 ios app bundle id 发送通知
【发布时间】:2017-11-07 02:05:39
【问题描述】:

我正在构建一个用于在 youtube 频道上上传视频的 api。其中一项要求是,每当视频成功上传到 youtube 服务器时,都必须使用 Firebase Cloud Messaging 向 ios app bundle id 发送通知。 我已经在 fcm 控制台中使用 bundle id com.tbox.ygtp 注册了我的应用程序 我曾尝试用谷歌搜索如何向 ios 应用程序发送通知,我发现以下 API

 $url = 'https://fcm.googleapis.com/fcm/send';
    $server_key = 'AAAAylThdyA:APA91bGISSU********VTqHJqBnV81B3jfJzAice07E********HHLXTVylMU1OWSHvdyoZMVNlM8t9p9tXH_4OKm********fEOatp_alw9qMlQNT507lLWLt1N_FMHel1JCCWcuQjD';

    $fields = array();
    //$fields['data'] = $data;
    $fields['notification'] = array('body'=>$data);
    if(is_array($target)){
        $fields['registration_ids'] = $target;
    }else{
        $fields['to'] = $target;
    }
    //header with content_type and api key
    $headers = array(
        'Content-Type:application/json',
      'Authorization:key='.$server_key
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);

    return $result;

此 Api 向设备令牌发送通知。但我需要在应用程序包 ID 上发送通知。 有人可以指导我如何使用 FCM 将通知发送到应用程序包 ID。

【问题讨论】:

    标签: javascript php firebase firebase-cloud-messaging


    【解决方案1】:

    目前没有任何 API 或参数可用于仅将消息发送到特定的捆绑包 ID。此选项仅在通过Firebase Notifications Console 发送消息时可用。

    作为一种解决方法,您可以利用Topic Messaging,通过为用户订阅主题(您可以将其命名为您的捆绑ID,或更简单的别名),然后只需使用主题名称向其发送消息用户。

    【讨论】:

    • 另请参阅我昨天对 Android 类似问题的回答:stackoverflow.com/questions/44364394/…
    • 谢谢普夫。复制这个会更好吗(因为想法几乎相同)?
    • 我认为将答案分开是可以的。我只是想链接它们,因为正如你所说的解决方案是相似的。
    猜你喜欢
    • 2020-11-03
    • 2019-07-21
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    相关资源
    最近更新 更多