gpt4 book ai didi

java - 如何使用 Spring Boot 向 iOS 应用程序发送推送通知

转载 作者:行者123 更新时间:2023-12-05 05:16:34 26 4
gpt4 key购买 nike

我想从我的 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 上收到它。

最佳答案

问题是您将通知发送到电子邮件而不是通知 token 。

    service.push(merchantObject.getEmail(), payload);

您需要从设备获取通知 token 并将其发送给该设备。

关于java - 如何使用 Spring Boot 向 iOS 应用程序发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50291416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com