我已将ios应用程序配置为prod和uat。结果,捆绑包ID是不同的,并且推送证书也不同。
我正在使用Firebase进行推送通知,并且在我的iOS中,我像这样配置我的plist。
func setUpFirebase() {
let filePath = Bundle.main.path(forResource: FIREBASE_PLIST, ofType: "plist")!
let options = FirebaseOptions(contentsOfFile: filePath)
FirebaseApp.configure(options: options!)
}
我也订阅这样的话题。
Messaging.messaging().subscribe(toTopic: "all")
我从后端发送这样的通知。
NotificationService.sendNotificationToTopic(notification, "all");
这是实现。我已经在使用 RESTRICTED_PACKAGE_NAME ,但它无法正常工作,并且会发送到所有软件包。我该怎么办?
public static void sendNotificationToTopic(Notification notification, String topic) throws JSONException, ClientProtocolException, IOException{
JSONObject notificationObject = new JSONObject();
notificationObject.put(Notification.TITLE, notification.getTitle());
notificationObject.put(Notification.TEXT, notification.getText());
notificationObject.put(Notification.ICON, notification.getIcon());
notificationObject.put(Notification.CLICK_ACTION, "FCM_PLUGIN_ACTIVITY");
JSONObject notificationData = new JSONObject();
notificationData.put(Notification.PAGE, notification.getPage()!=null?notification.getPage():"");
if (notification.getPageParam()!=null){
notificationData.put(Notification.PAGE_PARAM, notification.getPageParam());
}
JSONObject sendObject = new JSONObject();
sendObject.put(Notification.DATA, notificationData);
sendObject.put(Notification.NOTIFICATION, notificationObject);
sendObject.put(Notification.TO, "/topics/" + topic);
sendObject.put(Notification.RESTRICTED_PACKAGE_NAME, PACKAGE_NAME);
sendObject.put(Notification.PRIORITY, Notification.HIGH_PRIORITY);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost("https://fcm.googleapis.com/fcm/send");
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Authorization", "key=" + FCM_KEY);//todo for pro
HttpEntity entity = new StringEntity(sendObject.toString(),"UTF-8");
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity responseEntity = httpResponse.getEntity();
}