Push Notifications on iOS to a topic


I have an Ionic app (client), with a Java 8 backend (server), and I have set up push notifications.


        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: {}

For Android, I can receive notifications, send from the following:


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");
	// Send FCM message content.
	OutputStream outputStream = conn.getOutputStream();

	return "Android Push Notification: " + conn.getResponseCode() + " " + conn.getResponseMessage() + " - " + pushMessage;


I have the following code for iOS, but the client does not receive the push notifications.

 * 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()

	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;

If you look at the com.notnoop.apns api, it is supposed to push to a device token, however, I need it to rather push to a uid. I have implemented the above code to push to a uid, but it doesn’t work.


Id it possible for the com.notnoop.apns api to push notifications to a topic? Otherwise, is there another api that will be able to do this?

If neither is possible, should the client rather listen on the device token? But the problem here is, that the sender of the push notification does not know the receivers device token. The sender does know the receivers uid though.