Reputation: 621
I would like to send a push notification to my app from my springboot API. I have tried this code but its not working.
@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");
}
The code returns a success response however i do not get a push notification on my application. What am i missing in the code. When i send a push notification using Firebase i get it on my iphone.
Upvotes: 4
Views: 3221
Reputation: 40226
You need to confirm that your firewall have access to below sites,
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;
As notnoop/java-apns uses socket to fire push to apns server,
Upvotes: 0
Reputation: 1266
The problem is that you are sending the notification to an email instead of a notification token.
service.push(merchantObject.getEmail(), payload);
you need to get the notification token from the device and send it to that.
Upvotes: 2