Java iOS将通知推送到主题
我有一个带有Java8后端(服务器)的Ionic应用程序(客户端),并设置了推送通知Java iOS将通知推送到主题,java,ios,ionic-framework,push-notification,apple-push-notifications,Java,Ios,Ionic Framework,Push Notification,Apple Push Notifications,我有一个带有Java8后端(服务器)的Ionic应用程序(客户端),并设置了推送通知 /** * import com.notnoop.apns.APNS; import com.notnoop.apns.ApnsService; * https://github.com/notnoop/java-apns. */ private String sendIOSPushNotification(String device_token, String topics, String title,
/**
* import com.notnoop.apns.APNS; import com.notnoop.apns.ApnsService;
* https://github.com/notnoop/java-apns.
*/
private String sendIOSPushNotification(String device_token, String topics, String title, String message)
throws Exception {
ApnsService service = APNS.newService().withCert(PATH_TO_P12_CERT, CERT_PASSWORD).withSandboxDestination()
.build();
String payload = APNS.newPayload()
// .customFields(map)
.alertBody(title + " " + message).sound("default").build();
service.push(Utilities.encodeHex(topics.getBytes()), payload);
return "iOS Push Notification: " + title + " " + message;
}
客户端
let topics: string[] = [this.personModelLoggedIn.uid];
const options: PushOptions = {
android: {
senderID: "XXXXXXXXXXXX",
sound: "true",
vibrate: "true",
topics: topics
},
ios: {
senderID: "XXXXXXXXXXXX",
alert: "true",
badge: true,
sound: "true",
topics: topics
},
windows: {}
};
对于Android
,我可以通过以下方式接收通知:
服务器
private String sendAndroidPushNotification(String device_token, String topics, String title, String message)
throws Exception {
String pushMessage = null;
if (device_token != null && !device_token.equals("null")) {
pushMessage = "{\"data\":{\"title\":\"" + title + "\",\"message\":\"" + message + "\"},\"to\":\""
+ device_token + "\"}";
} else {
pushMessage = "{\"data\":{\"title\":\"" + title + "\",\"message\":\"" + message + "\"},\"to\": \"/topics/"
+ topics + "\"}";
}
// Create connection to send FCM Message request.
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + SERVER_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// Send FCM message content.
OutputStream outputStream = conn.getOutputStream();
outputStream.write(pushMessage.getBytes());
return "Android Push Notification: " + conn.getResponseCode() + " " + conn.getResponseMessage() + " - " + pushMessage;
}
问题
我有以下用于iOS
的代码,但是客户端没有收到推送通知
/**
* import com.notnoop.apns.APNS; import com.notnoop.apns.ApnsService;
* https://github.com/notnoop/java-apns.
*/
private String sendIOSPushNotification(String device_token, String topics, String title, String message)
throws Exception {
ApnsService service = APNS.newService().withCert(PATH_TO_P12_CERT, CERT_PASSWORD).withSandboxDestination()
.build();
String payload = APNS.newPayload()
// .customFields(map)
.alertBody(title + " " + message).sound("default").build();
service.push(Utilities.encodeHex(topics.getBytes()), payload);
return "iOS Push Notification: " + title + " " + message;
}
如果您查看com.notnoop.apns
api,它应该推送到设备令牌
,但是,我需要它推送到uid
。我已经实现了上面的代码来推送到一个uid
,但是它不起作用
问题
com.notnoop.apns
api是否可以将通知推送到主题?否则,是否有其他api能够做到这一点
如果两者都不可能,客户端是否应该监听设备令牌
?但这里的问题是,推送通知的发送者不知道接收者设备令牌。但是发送者确实知道接收者uid
谢谢