我目前正在开发两个不同的应用程序但在单个硬件设备上测试它们(因为这是我的使用场景之一) - 我在StackOverflow on how to send notifications to one of two apps in the same project at firebase上看到过类似的问题
但是,在我的情况下,我有两个不同的应用程序(具有不同的包名称),并希望能够在使用push_service.notify_single_device()时区分。
从上一个问题我明白我可以使用restricted_package_name
但经过大量的谷歌搜索后,我还没有找到任何示例代码。我该如何使用它?
以下用法是否正确?
pushresult = push_service.notify_single_device(registration_id=requester_fcm_key,
message_title="Message Title",
message_body="Please hold on while we connect you",
restricted_package_name='com.domain.packagename',
data_message=requester_data_message)
如果有人可以分享一些我可以看一下并理解的示例/示例代码,那就太好了。
在寻找答案的同时,我放宽了搜索范围以包含其他语言的FCM用法,果然,我在stefanhoth's GitHub page找到了一个PHP示例
$fields = array(
'registration_ids' => $registrationIDs,
'restricted_package_name' => 'com.example.myandroidapp',
'collapse_key' => 'somekey_'.$messageType,
'data' => array( "KEY_GCM_MESSAGE_TYPE" => $messageType,
"payload" => $message ),
);