Could not get the apid in the client side/js - android

I m using Urbanairship with Phonegap. The push messaging is working fine in many cases but I m having problem capturing the "APID" in the client side.
The device is registered and APID is generated but when I try to call the registerEvent in the javascript, the push object is empty and the function is not called.
push = window.pushNotification; //this returns an object
push.registerEvent('registration', function (error, id) {//this is never fired
I m using PhoneGap 2.9
//in the config.xml
<plugin name="PushNotificationPlugin" value="com.urbanairship.phonegap.plugins.PushNotificationPlugin" onload="true"/>
If I copy the APID from the logcat(eclipse) and use it, the messaging is working. The only problem is I m not able to get the APID in my client side
Please help

You need to use Phonegap 3.0, as stated on the Github page, and if you look at the Example/index.html you can see that they get the push object using:
var push = window.plugins.pushNotification;
Then push.registerEvent('registration', callback) should work.

Related

Mobilefirst PushNotification: On using wl_anonymousUserRealm at server, app is not calling onReceive method on clicking notification

I am working on IBM Mobilefirst native android app. I have written code to enable push notification. I am getting notification but I have an issue here.
On Launch of the app I am calling following code.
final WLClient client = WLClient.getInstance();
push = client.getPush();
ResponseListener listener = new ResponseListener(ResponseListener.AUTHENTICITY_CONNECT);
client.getPush().setOnReadyToSubscribeListener(listener);
challengeHandler = new AndroidChallengeHandler(realm);
client.registerChallengeHandler(challengeHandler);
WLRequestOptions options=new WLRequestOptions();
options.setAppUserId("sample");
client.connect(listener,options);
When I launch the app for the first time all the above code gets executed and the listener calls the below method
#Override
public void onReadyToSubscribe() {
WLClient.getInstance().getPush().registerEventSourceCallback(pushAliasName, "PushAdapter","PushEventSource", this);
}
After this listener is getting executed i am calling subscribe method. I get success for the subscription to push.
On the server side I call the procedure to send the push notification and it reaches the phone.
Now when my app goes to background and I get a notification . I click on the notification and app restarts and never call onRecieve method of the registered interface.
On click of the notification it relaunches the app and call the onReadyToSubscribe() again and it never calls the onRecieve method. what should I do to get the onReceive() method to be called and app shouldn't get relaunched(if app is already in background) on click of notification?
My server side security test is as below
<customSecurityTest name="AuthSecurityTest">
<test realm="wl_antiXSRFRealm" step="1"/>
<test realm="wl_authenticityRealm" step="1"/>
<test realm="wl_remoteDisableRealm" step="1"/>
<test realm="wl_anonymousUserRealm" isInternalUserID="true" step="1"/>
<test realm="wl_deviceAutoProvisioningRealm" step="2" isInternalDeviceID="true"/>
</customSecurityTest>
The useridentity is not binded to security test but i am putting it in the apps applicationdescriptor. So it never call for credentials required of challenge handler on connect.
Here I think this could be the issue in the sample code that is provided by MFP in 7.1 version security test has useridentity realm but in my case I am not using the custom useridentity realm but I am using the default wl_anonymousUserRealm. This is the issue because when i tried working with the sample code it works completely fine with all the scenarios. But with the wl_anonymousUserRealm I have this issue.
onReadyToSubscribe() method getting called everytime the application connects to the server ( even if already subscribed for push) is expected and by design.
onReadyToSubscribe() is a call back that fires at the client denoting the token exchange between client and server is complete. This is required because tokens issued to an application by mediator can change. This makes it imperative that the server always stays updated with the latest token. If not , push notification will fail with invalid token error.
When the client connects to the server , they compare tokens - client presents the token it has now and server presents what it had stored. Three cases happen:
1) In a new registration , server does not have a token. Here client passes on what it got from the mediator, server persists it and issues a success. Client fires the onReadyToSubscribe() callback to indicate push handshake is complete and client can now subscribe to aliases or tags.
2) Client has received a new token from the mediator. This does not match the one server already has. Client passes on the new token to server, server updates its records with the new token and lets the client know. onReadyToSubscribe() call back fires at client indicating successful handshake. Earlier subscriptions records stay.
3)If the tokens match, then onReadyToSubscribe() fires denoting that push handshake is complete (no changes required)
Thanks to Vivin for the suggestions.
Here was the issue in the sample code that is provided by MFP in 7.1 version security test has useridentity realm but in my case I am not using the custom useridentity realm but I am using the default wl_anonymousUserRealm.
The actual issue was wl_anonymousUserRealm generates a new random userid everytime. So when ever my app is relaunched my userid gets changed and I wont get push in onrecieve because it thinks a different user is logged into the app..
Now because I cant change the wl_anonymousUserRealm I am sending push using deviceid. Please check the below link(Adapter code as below).
https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html#sendMessage
check sample client code from below link.
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.1/notifications/push-notifications-overview/push-notifications-native-android-applications/tag-based-notifications-in-native-android-applications/

get include_player_ids params values for POST request in Postman

I'm working on Remote Notifications in my Ionic App using OneSignal.
I have created an App in OneSignal, configured it for my app and initiated the service as per the Official Docs.
To test this, I am using Postman Chrome Extension. So, after adding the POST Request URL, where can I find the String values for the include_player_ids key.
I have my app still in testing state.
What's the code in typescript to get the value of include_player_ids from our Mobile Device?
Assuming you are using the OneSignal Native Android SDK, you should use the OneSignal idsAvailable method to get the device's OneSignal Player Id and then pass this value to your server.
window.plugins.OneSignal.getIds(function(ids) {
console.log('getIds: ' , ids);
self.deviceToken = ids.pushToken;
self.userId = ids.userId;
console.log(self.userId);
});
That gives u deviceToken and OneSignal User ID, which is referred to as Player ID
I copied the value from the console and used!
Thanks #Saiy2k

Cordova/Phonegap push notifications - custom template accessing payload

I am building an Ionic app with VS2015 (cordova/phonegap), and using the push notification plugin. There is no problem in the actual functionality of the push notifications, I get them correctly and they are displayed to our customers.
What I am trying to do is to get the title and/or id from the payload of the notification.
The registration code is as follows:
var template = '{ "data" : {"message":"$(message)", "id": "$(id)", "title": "$(title)"}}';
// Register for
mobileServiceClient.push.gcm.registerTemplate(e.regid,"CT2", template, NOTIFICATION_TAGS_ARRAY)
When I try to access the notification (in function onGCMNotification(e)) I can only see the message and all other params in the payload are undefined (if I try accessing e.payload.id)
Can anyone help me?
Note: I am using the phonegap push plugin - not the Ionic one.
UPDATE:
I finally got it to work once, but just for the first notification - so we still have the problem.
What happened was as following:
I uninstalled the app and re-installed it.
Re-registered my custom template.
Results are that I get the notification twice:
First time - payload contains only message (not other attributes)
Second time - I get the complete payload with extra attributes.
Next time we send a notification and any other time - we get only the message in the payload without the rest of the attributes.
Cordova version 5.1.1

onNotification method not called

I am trying to use Ionic Push for Push Notifications. I have successfully registered with the server and got the Token ID also (Called reg_id in Ionic).
I have followed all the steps as shown in Ionic Docs here http://docs.ionic.io/v1.0/docs/push-install.
But now when I try to send push notifications using the curl command, the notification is shown as sent but is never received by the app. If I check the status, I get the status as success. Please help
Comtroller Code: https://gist.github.com/samarthagarwal/833064a2de0660e826b6
Any suggestions are highly appreciated.

payload is null from server

In my app receives the push notification from GCM(for android) everything is fine am getting the notification but the payload is null. Cross checked server side script it's fine. This is the response am getting in callback method
This is the GCM response
{"type":"callback",
"source":{"pushType":"gcm", "invocationAPIs":[],
"showAppOnTrayClick":true,
singleCallback":false,
"__propertiesDefined__":true,
"bubbleParent":true,
"_events":{"callback":{},
"trayClickLaunchedApp":{},
"trayClickFocusedApp":{}},
"focusAppOnPush":false,
"enabled":false,
"showTrayNotificationsWhenFocused":false,
"apiName":"Ti.Module",
"showTrayNotification":true,"debug":false},
"payload":"","bubbles":false,
"cancelBubble":false}
Am using Titanium 3.5.1GA and tried with ti.cloudpush(3.3.7) same issues .
How can i solve it?
Since the notification does arrive it's probably not an error in the app but on the server sending the payload. Try one of the several (online) apps to test notifications on Google.

Categories

Resources