我想从springboot API向我的应用发送推送通知。我试过这个代码,但它没有用。
@RestController
public class NotificationController {
ApnsService service =
APNS.newService()
.withCert("/Users/User/Documents/Personal_Projects/Api/src/main/resources/Certificates.p12", "a")
.withSandboxDestination()
.build();
String payload = APNS.newPayload()
.alertBody("My first notification\nHello, I'm push notification")
.sound("default")
.build();
service.push(merchantObject.getEmail(), payload);
System.out.println("The message has been hopefully sent...");
return new Response("", "Sent successfully");
}
代码返回成功响应但是我没有在我的应用程序上获得推送通知。我在代码中缺少什么。当我使用Firebase发送推送通知时,我会在我的iphone上发送。
答案 0 :(得分:0)
问题是您正在将通知发送到电子邮件,而不是通知令牌。
service.push(merchantObject.getEmail(), payload);
您需要从设备获取通知令牌并将其发送到该通知令牌。
答案 1 :(得分:0)
您需要确认防火墙可以访问以下站点,
public static final String SANDBOX_GATEWAY_HOST = "gateway.sandbox.push.apple.com";
public static final int SANDBOX_GATEWAY_PORT = 2195;
public static final String SANDBOX_FEEDBACK_HOST = "feedback.sandbox.push.apple.com";
public static final int SANDBOX_FEEDBACK_PORT = 2196;
public static final String PRODUCTION_GATEWAY_HOST = "gateway.push.apple.com";
public static final int PRODUCTION_GATEWAY_PORT = 2195;
public static final String PRODUCTION_FEEDBACK_HOST = "feedback.push.apple.com";
public static final int PRODUCTION_FEEDBACK_PORT = 2196;
notnoop/java-apns使用套接字将推送到APNS服务器,