arleyandrada / PushClient

FREE and Open Source - Titanium PushClient Module
Other
44 stars 17 forks source link

Push notification in foreground #87

Closed somefakeuser closed 9 years ago

somefakeuser commented 9 years ago

Hi Arley,

We are using the module inside an Android App and everything works fine. Actually we are developing IOS side, and we have problems with the module. We configure the project as examples, but only received notifications when the app is in background and we send the notification from server with alert body. Only work the mode_click event and we need the callback from mode_foreground and mode_background to take some data from payload (in Android works fine). Also we need to receive the notification without alert body, only the data, for manage ourself. We are reading in many forums, but any solution works.

Is posible do what we want? We believe that the module is correct configurated for IOS but we dont know exactly.

Sorry for my english!!!!!

Regards.

arleyandrada commented 9 years ago

When the app is running in foreground iOS does not put the notification in the notification center (this is possible on Android but unfortunately not on iOS), but the event CALLBACK is fired with the payload data.

For further questions, may help you access the GitHub repository, which I published, with a sample project and the entire history of solved issues:

https://github.com/arleyandrada/PushClient

Regards,

Arley

J0nAnder commented 9 years ago

Hi again Arley,

We are trying to get the callback event fired when the app is in foreground but there is no way.

Only click callback is fired and only if the app is just installed on iOS device. I don't know if all is correctly configured, but i test again on android and everything works fine.

I use the code in the doc to make this run, here you can see a fragment of my code (eventCallback) which is on "app.js":

var eventCallback = function(event) {
        if (!event) {
            Ti.API.info('Callback:\n\nInvalid callback');
        } else if (event.mode == PushClient.MODE_FOREGROUND) {
            Ti.API.info('Callback in Foreground:\n\n' + JSON.stringify(event.data));
        } else if (event.mode == PushClient.MODE_CLICK) {
            Ti.API.info('Callback from Click:\n\n' + JSON.stringify(event.data));
        } else if (event.mode == PushClient.MODE_BACKGROUND) {
            PushClient.endBackgroundHandler(event.data.handlerId);
            Ti.API.info('Callback from Silent:\n\n' + JSON.stringify(event.data));
        } else if (event.mode == PushClient.MODE_ACTION) {
            Ti.API.info('Callback from Action:\n\n' + event.category + '\n' + event.identifier + '\n\n' + JSON.stringify(event.data));
        } else {
            Ti.API.info('Callback:\n\n' + JSON.stringify(event.data));
        }
    };

    PushClient.addEventListener(PushClient.EVENT_SUCCESS, eventSuccess);
    PushClient.addEventListener(PushClient.EVENT_ERROR, eventError);
    PushClient.addEventListener(PushClient.EVENT_CALLBACK, eventCallback);

    PushClient.registerPush(registerOptions);

In the "tiapp.xml" i add the next lines

<key>UIBackgroundModes</key>
      <array>
           <string>remote-notification</string>
      </array>

I don't know if i need to configure something else in my proyect.

Thanks in advance!

arleyandrada commented 9 years ago

Apparently that's OK in your code and it should work receiving notifications in the foreground on iOS.

The "remote-notification" settings is used for background notifications on iOS, but it does not affect the foreground callback.

There is no any other required configuration.

Maybe you can share your project or at least your app.js file (full).

Can you share your app console log (full) when it receives push notification in foreground and in background?

J0nAnder commented 9 years ago

Hi again Arley.

At this time I can not send you the code, but on Monday I'll write you with the requested code.

At the moment, we have sucessfully recieved notifications (Click_Mode and Foreground_Mode) but still we don't get notifications on Background_Mode.

The problem about callback seems to be at the moment that we call your module code. That part seems solved, but still no Background_Mode callback is triggered from the module.

Thanks again and have a nice weekend!

arleyandrada commented 9 years ago

To enable background push notification in iOS include the "content-available" attribute in your sent payload data.

Something like that:

{
"content-available" : 1,
"my-custom-attr" : "some-value"
}

To enable iOS background push notification, set the UIBackgroundModes in tiapp.xml

    <ios>
        <plist>
            <dict>
                .....
                <key>UIBackgroundModes</key>
                <array>
                    <string>remote-notification</string>
                </array>

That's all!

Regards,

Arley

J0nAnder commented 9 years ago

Hi again,

I dont try that atribute on the payload, that could be the solution :).

The UIBackgroundModes key is on that place of the tiapp.XML.

On monday i'll write you with the progress.

Best regards,

Jon Ander

J0nAnder commented 9 years ago

Hi Arley,

I try the "content-available" attribute and that's the point!, Background_Mode is fired from callback :+1:

Now all my notifications are working.

Thank you very much for the assistance, your module is amazing.

Best regards,

Jon Ander