Mobilefirst 8.0 Push notification get Device ID - ibm-mobilefirst

I am using Mobilefirst 8.0 push notification part in cordova application downloaded sample application which is given by IBM. Its working fine.
When I click on register device button device id I can see in mobilefirst console.
1) How I can get that same device ID in client side application?
2) User ID field also I can see in mobilefirst console device register information. How Can I add particular User ID while registering device?

1) How I can get that same device ID in client side application?
You can call the following REST endpoint in order to retrieve from the server various data about the application, including the deviceId: http://www.ibm.com/support/knowledgecenter/en/SSHS8R_8.0.0/com.ibm.worklight.apiref.doc/rest_runtime/r_restapi_push_device_registrations_get.html
2) User ID field also I can see in mobilefirst console device register information. How Can I add particular User ID while registering device?
The sample uses the MobileFirst security framework, and that's where the userId is coming from. Please refer to the security documentation, tutorials and samples:
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/user-authentication/android/
The same userId is also used by the Push service by default (Push retrieves the user id from the request being made and if the user is already logged in, the userid part of the request). If there is no challenge handler in place the default user id would be anonymous.

Related

APNS handle obtained by Expo in React Native is incorrect

EXPO SDK Version: 42.0.01
Developing for: iOS
Our goal: successfully send a test notification from Test Send tool in Azure Notification Hub to a registered physical iPhone which is running a local instance of an EXPO app.
Progress: we're able to successfully register a physical iPhone with Azure Notification Hub without using a 3rd party library. We can see that registration in the Hub.
Issues: when using the Azure's Test Send tool we're getting an error "The Push Notification System handle for the registration is invalid" and the test notification does not get delivered.
Debugging:
we're using EXPO's Notifications.getDevicePushTokenAsync() API to obtain the push token.
Azure support team analysed the logs and concluded that the problem is the PNS handle i.e. Apple's ID of the phone registered for notifications.
the phone's PNS handle remains the same at all times.
by using "expo credentials:manager" I've added a new Push Notification Key using KeyID, TeamID and .p8 certificate - the PNS handle didn't change after doing that and notifications were failing too.
I haven't found any tools to validate the APNS handle. I'm currently awaiting a .p12 certificate from our corporate team to test notifications by using https://pushtry.com/.
How do we validate the APNS handle and if found that it's invalid - how do we cycle it / request another?
The PNS Handle from APNs does not change that often as it is tied to the device and app installation. See this answer for more details Does the APNS device token ever change, once created?

Developer payload (external data) in App Store server notifications

We are using server-to-server purchase notifications for Google Play and App Store mobile apps. User can pay for subscription in several ways: in web broswer (via third-party billing provider), in android application (via google play) and in ios/macos application (via app store). That is why we use custom user/subscription ids - it should be equal across all platforms/devices within single account.
Now, everhing went just fine with other billing providers until we came to App Store. We configured server side notification with callback at our server as we did it before. And now it turns out, that there is no user information in App Store receipt data. And it seems to be no way to pass that data from mobile application. For example, Google Play have so called "developer payload" field for this purposes, other providers also have possibility to add external data into server notification request. Is there any analog for App Store notifications?
Another question is about notifications itself. If there is no user information in the receipt - that means that there is no way to bind user id and receipt id data. Then what is the purpose of such notfications with external server scenario?

Mobilefirst 8.0 Push notification Implemantation

I have made simple application using Ionic and cordova. Added Mobilefirst plugin in it. Also I have used security adapters in it ResourceAdapter and UserLogin Adapter which is provided by IBM.
Now I want to include push notification part in this project. So I have added push notificationMFP plugin in same project. Sender id and key in push settings. Added scope push.mobileclient also.
When I tried to call MFPPush.registerDevice javascript method I am getting failed to register device.
Failed to register device:"com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushException: Response: Status=404, Text: Error 404: SRVE0295E: Error reported: 404\n, Error Message: Not Found"
Also when App get initialized I can see in MFP console that particular device in devices list and when I login I can see user ID also get added in device information. So what is problem is something I am missing? Why device is not able to register for push?
The original issue in the question was resolved:
Yes. Now its working Its initialization issue. Just got it. Thnks.
The user then added a new issue via comments:
One more help I need. I am trying to send notification to particular User ID through MFP console. But device can not get any notification. But i cn see User ID against device id. So there is option to send to user id in console. But its not working for me
Unless you got an error in the console, this means that the notification in all likelyhood left the MobileFirst Server. From there there are numerous options why the sending will fail. See the Push Notifications Troubleshooting section.

Gcm with appodeal

I am using gcm with appodeal in my app and when I am sending the push notification the for the first push was successful but phone is not receiving the notification and after that error is there while sending push that device is not register. What to do in this situation please help me.
Is it iOS or Android ? I had the exact same issue just yesterday with iOS and all I had to was to create a development provisioning profile and set it up properly in xCode. I hope that helps you.
I think for you to verify that your app can send and receive messages, client apps must register with GCM.
To register with GCM:
1.The client app obtains a registration token using the Instance ID API. The call to this API must have the authorized entity set to your app server's sender ID, and the scope set to the appropriate value for GCM (depending on your platform). Refer to the API reference for full detail on this API.
2.The client app passes the registration token to the app server.
3. The app server saves the registration token and acknowledges to the client app that the process completed successfully.
This thread may also provide further insight as to why you are receiving the device not registered error.

Should i backup GCM registration ID with google cloud?

Is it advised to backup GCM id using android cloud back up ? i am storing the GCM id in a sharedpreferences so i dont have to keep registering.
if i backup this GCM sharedpref and user changes devices do i need to update it to a new registration id ? Is the registration ID device specific ? What happens when user changes devices and backs up ?
I tried and read this from the docs:
You must exclude any device specific identifiers, either issued by a server or generated on the device. This includes the Google Cloud Messaging (GCM) registration token which, when restored to another device, can render your app on that device unable to receive GCM messages.
From the docs i found my answer that the reason this should not be done is that it can intrefer in the apps intialization of gcm and it will not try to get the GCM id if its already restored from a new device that restored a old registration id.
Handle Google Cloud Messaging
For apps that use Google Cloud Messaging (GCM) for push notifications,
backing up the registration token that Google Cloud Messaging
registration returned can cause unexpected behavior in notifications
for the restored app. This is because when a user installs your app on
a new device, the app must query the GCM API for a new registration
token. If the old registration is present, because the system had
backed it up and restored it, the app doesn't seek the new token. To
prevent this issue from arising, exclude the registration token from
the set of backed-up files.