java-apns icon indicating copy to clipboard operation
java-apns copied to clipboard

Push Notification issue

Open ghost opened this issue 10 years ago • 12 comments

I am using following code, but not showing any error nor notifications.I've added in this source code, but not working. What could be the reason of failure? Please help on this.

public class Demo {
    ApnsService pushService = APNS.newService()
            .withCert("cert.p12", "password")
            .withSandboxDestination()
            .build();

    void notify(String message){
        String payload = APNS.newPayload().alertBody(message).badge(45).sound("default").build();
        String token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        pushService.push(token, payload);

        Map<String, Date> inactiveDevices = pushService.getInactiveDevices();
        for (String deviceToken : inactiveDevices.keySet()) {
            Date inactiveAsOf = inactiveDevices.get(deviceToken);
            System.out.println("Output : " + inactiveAsOf);
        }
    }
}

ghost avatar Jun 10 '15 16:06 ghost

whats exactly the issue ?

matzew avatar Jun 10 '15 16:06 matzew

When I run above code, I neither see error message and nor see notifications coming to iOS device.

  1. How can we confirm connection is establish with gateway.sandbox.push.apple.com.
  2. How we confirm push notifications being sent to iOS device.

Also, as I said above code not working for me, don't see any errors and notification. What could be the reason of failure?

ghost avatar Jun 10 '15 19:06 ghost

@pashtika you could implement this interface https://github.com/notnoop/java-apns/blob/master/src/main/java/com/notnoop/apns/ApnsDelegate.java

and include it when building the ApnsService e.g.:

APNS.newService()
  .withXXXXX().
.....
. withDelegate(new ApnsDelegate() {
/// implement the methods
})

matzew avatar Jun 11 '15 06:06 matzew

@pashtika firstly you need to verify your security certificate generate by mac machine.

harmeetsingh0013 avatar Jun 30 '15 19:06 harmeetsingh0013

yes, OK, I am able to send notification to Apple IOS device. But how can I send emoji and different sound through APNS java code?

ghost avatar Jun 30 '15 19:06 ghost

that's good, @pashtika for this, i have no idea. you will need to explore Java APNS libraries, or use another one. If you did this, please notify us.

harmeetsingh0013 avatar Jun 30 '15 19:06 harmeetsingh0013

Perhaps worth to look at Apple's APNs doc? https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

matzew avatar Jun 30 '15 21:06 matzew

Is there any way to confirm whether notifications being send successfully through APNS java code? Let me explain more: Suppose, I don't have iOS device with me and it's with some other person and I want to send APNS push notification to that person, Do I've a way to confirm notifications being send successfully to that person through APNS Java API rather than I need to ask that person to confirm if he/she has received notification?

Please let me know if we can confirm notifications being send successfully thorough java code? I can get confirmation in the case of GCM in response.

ghost avatar Jul 09 '15 11:07 ghost

to device? no - well, not directly via apns api

to apns itself: yes (see the ApnsDelegate interface I mentioned on a different thread before)

On Thursday, July 9, 2015, pashtika [email protected] wrote:

Is there any way to confirm whether notifications being send successfully though APNS java code?

— Reply to this email directly or view it on GitHub https://github.com/notnoop/java-apns/issues/241#issuecomment-119924169.

Sent from Gmail Mobile

matzew avatar Jul 09 '15 17:07 matzew

Could you please share code snippet, how we can use APNSDelegate to know Notifications being sent on iOS device within APNS API?

ghost avatar Oct 21 '15 11:10 ghost

@JavaHelper you can implement ApnsDelegate's messageSent method. if the message was sent to APNS successfully, this method would be called.this means that the message was accepted by the APNS.

However, it's almost impossible to check that whether the message was arrived at the specified device,because apple doesn't guarantee this.what we only know is that APNS will attempt to send the message,that's it.

justuno avatar Dec 03 '15 11:12 justuno

On Thu, Dec 3, 2015 at 12:39 PM, Justuno [email protected] wrote:

@JavaHelper https://github.com/JavaHelper you can implement ApnsDelegate's messageSent method. if the message was sent to APNS successfully, this method would be called.this means that the message was accepted by the APNS.

However, it's almost impossible to check that whether the message was arrived at the specified device,because apple doesn't guarantee this.what we only know is that APNS will attempt to send the message,that's it.

Right, but you can build your own layer around (e.g. ping your backend from the app). That's what we have done for our AeroGear push server: * https://aerogear.org/docs/unifiedpush/ups_userguide/index/#_pushapplication_analytics * https://aerogear.org/docs/unifiedpush/ups_userguide/index/#_pushapplication_activity

— Reply to this email directly or view it on GitHub https://github.com/notnoop/java-apns/issues/241#issuecomment-161606728.

Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/ sessions: http://www.slideshare.net/mwessendorf twitter: http://twitter.com/mwessendorf

matzew avatar Dec 03 '15 12:12 matzew