1

I am building an api to upload video on youtube channel. One of the requirement is that whenever a video is uploaded successfully to youtube server a notification must be sent to the ios app bundle id using Firebase Cloud Messaging. I have registered my application in fcm console with bundle id com.tbox.ygtp I have tried to google on how to send notification to the ios app and i found following 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;

This Api sends notification to device tokens. But I need the notification to be sent on application bundle id. Can someone guide me through how to send the notification to application bundle id using FCM.

1 Answers1

1

There is currently no API or parameter you could use to send a message only to a specific bundle id. This option is only available when sending the message through Firebase Notifications Console.

As a workaround, you could make use of Topic Messaging, by subscribing the users to the topic (where you could name as your bundle id, or a simpler alias), then simply use the topic name to send a message to the users.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    Also see my answer to a similar question for Android yesterday: https://stackoverflow.com/questions/44364394/how-to-send-firebase-message-to-specific-application-in-project/44364798#44364798 – Frank van Puffelen Jun 06 '17 at 08:03
  • Thanks Puf. Would it be preferable to have this duplicated (since the idea is pretty much the same)? – AL. Jun 06 '17 at 08:07
  • 1
    I think it's fine to keep the answer separate. I just wanted to link them, since as you said the solution is similar. – Frank van Puffelen Jun 06 '17 at 08:16