Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a Pushnotification to an iOS app using Springboot

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.

like image 907
Erent Avatar asked Oct 29 '25 12:10

Erent


1 Answers

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.

like image 77
Todoy Avatar answered Oct 31 '25 02:10

Todoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!