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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With