Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java iOS将通知推送到主题_Java_Ios_Ionic Framework_Push Notification_Apple Push Notifications - Fatal编程技术网

Java iOS将通知推送到主题

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,

我有一个带有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, 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

谢谢