iOS推送通知到主题

时间:2017-06-27 12:52:14

标签: java ios ionic-framework push-notification apple-push-notifications

我有一个Ionic应用程序(客户端),带有Java 8后端(服务器),我已经设置了推送通知。

客户端

        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,它应该推送到device token,但是,我需要它而不是推送到uid。我已经实现了上面的代码以推送到uid,但它不起作用。

问题

我认为com.notnoop.apns api可以将通知推送到某个主题吗?否则,是否有其他api能够做到这一点?

如果两者都不可能,客户应该倾听device token吗?但问题是,推送通知的发送者不知道接收者device token。发件人确实知道接收器uid

由于

0 个答案:

没有答案