distriqt / airnativeextensions

DEPRECATED: Original repository of the distriqt native extensions and is no longer maintained. Please see our site for the latest ANEs
https://airnativeextensions.com
2 stars 0 forks source link

How do I get payload if I start app by clicking on PUSH notification? #252

Closed minimedj closed 9 years ago

minimedj commented 9 years ago

Hi guys, I send PUSH from server with some payload. How do I get it is I start app from PUSH (I click on the push on device and app starts)?

p.s. If app is started and minimized - I have no problem with getting payload.

marchbold commented 9 years ago

Hi,

Add your notification event listener and call register. The notification that started the application will be dispatched immediately after calling register (if the application was started from a notification).

http://docs.airnativeextensions.com/pushnotifications/docs/com/distriqt/extension/pushnotifications/PushNotifications.html#register()

Some code:

PushNotifications.service.addEventListener( PushNotificationEvent.NOTIFICATION, notificationHandler );
PushNotifications.service.register( GCM_SENDER_ID );

Then in your handler:

private function notificationHandler( event:PushNotificationEvent ):void
{
    // Handle your start up notification
}
minimedj commented 9 years ago

I read in FAQ here (https://docs.google.com/document/d/1C3LltzyzZX96cyq69Lz1vuEVxD4erQhTwyBQeGrjCTs/pub):

Will the extension help to open the mobile app in a specific place once the notification received?

This is unavailable at the moment. Due to the way native extensions are implemented, we don't have access to the application startup options so we can't receive application startup notifications. You'll need to check your server for notifications at startup.

So, for me it is still unclear where it is limitation of your ANE, or of AIR platform itself?

marchbold commented 9 years ago

Thanks for pointing that out, I figured out a way around it a while ago, so I'll make sure that documentation gets updated.

minimedj commented 9 years ago

@marchbold thank you for your answer but it not relevant for me. As I wrote I have no problems with notifications if my app is running. I only have problems with payload when I am starting my app from push notification.

minimedj commented 9 years ago

@marchbold so, please give me a clear answer: can I get PUSH's payload when I start app from PUSH?

marchbold commented 9 years ago

Hi,

I did understand your situation and the answer above is for when an application is started from a push notification. The register function checks for a startup notification and dispatches the event immediately.

Regards, Michael

minimedj commented 9 years ago

@marchbold My situation is the following:

  1. I have my iOS device without any application running (nothing is deactivated).
  2. I get PUSH from server for my app.
  3. I click on PUSH
  4. My app starts...
  5. PROBLEM: I don't see payload....

Another scenario:

  1. I have my iOS device with my app being deactivated.
  2. I get PUSH from server for my app.
  3. I click on PUSH
  4. My app starts gets activated...
  5. I do see payload.

Any ideas why it is like this?

marchbold commented 9 years ago

Are you using the method I described above?

minimedj commented 9 years ago

Yes. 100% the same code as you provided. After some debugging I see that the problem is that event.data == null in this callback handler:

private function notificationHandler( event:PushNotificationEvent ):void
{
    // Handle your start up notification
}

So I get:

ERROR:: Error #1009: Cannot access a property or method of a null object reference.
marchbold commented 9 years ago

Can you provide an example of the payload you are using?

Also would be helpful to know the platform you are using, and can you obtain the device logs when you receive and click on a notification?

minimedj commented 9 years ago

@marchbold To make it 100% clear that this is issue of ANE I will me a demo project. As soon as I nail the problem I will report it here. Thank you very much for your help!

minimedj commented 9 years ago

@marchbold I confirm that everything works as expected. Thank you very much.

marchbold commented 9 years ago

Glad to hear! Would you mind sharing with everyone what your problem was in case someone else comes across this? Cheers