Erent
Erent

Reputation: 621

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.

Upvotes: 4

Views: 3221

Answers (2)

Sazzad Hissain Khan
Sazzad Hissain Khan

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

Todoy
Todoy

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

Related Questions