Push Notifications in Ionic 2 - ionic-framework

I am building a Chat application in Ionic 2, and need to implement Push Notifications.
Due to the fact that Google have recently moved their GCM service to rather use FCM, there is not much documentation how to implement an Ionic app with it. I have found the following tutorial which looks to do exactly what I need.
The tutorial seems good, however, I am confused on a few issues, and any help would be appreciated.
I am developing on a Windows machine, so currently just building for Android.
Question 1
I am confused with the following statement:
Build and run on real android and iOS devices to see device token in
console.
When I run ionic build android, it does not generate a device token in the console. Do you know how I can see what the device token is?
Or, is it just generated at run time by data.registrationId, and this is passed to the server?
push.on('registration', (data) => {
console.log("device token ->", data.registrationId);
//TODO - send device token to server
});
Question 2
In the Java,
static String API_KEY = "YOUR_GCM_API_KEY";
static String device_token = "YOUR_DEVICE_TOKEN";
For static String API_KEY = "YOUR_GCM_API_KEY";, is the YOUR_GCM_API_KEY the Server Key or Sender ID from FCM?
Is the static String device_token = "YOUR_DEVICE_TOKEN"; received from the Ionic app when you do this: console.log("device token ->", data.registrationId);? i.e. Is it passed from the client to the server?
Question 3
If we are sending separate messages to individual devices, e.g. for a Chat App, how do we differentiate between devices? Each chat message has an id associating it with a unique pair of users (e.g.[userId1,userId2]), but your example uses a device token, how do you send it for the unique user pair rather?
Question 4
I get the following at run time in the browser.
EXCEPTION: Error: Uncaught (in promise): TypeError: push.on is not a function
Can I ignore this? I suspect it is only happening in a browser and I won't get this error when it runs on a real devise.
UPDATE
It looks like all questions, apart from Question 3 have been answered below. I am guessing it can be done with some sort of pub/sub model on a key that's unique to the chat.

Question 1
It is a devise token passed from client to server: data.registrationId.
Question 2
YOUR_GCM_API_KEY is the Server Key generated by the FCM.
YOUR_DEVICE_TOKEN is passed from the client: data.registrationId.
Question 3
Not sure yet, am investigating further?
Question 4
The error can be ignored, it does not occur on a devise.

I haven't tried ionic before, but I'm gonna go on ahead and try to give my ideas with regards to your questions where I think some will be at the very least helpful:
Pretty sure that simply means to run the app on an actual device, not an emulator or a browser. Given the name, I think the reason why they're requiring to run an actual device is because maybe it is an ID that is retrieved from the device itself.
It's the Server Key. NOTE: You should ALWAYS keep the Server Key and Sender ID a secret.
For GCM/FCM one thing that is commonly used is a registration_token, which I think in this case, is the counterpart for the device token.
Not sure with this one. I did see this similar post, though it's still unresolved. Do look around the community, there might be another post similar to it.

Related

how to kick someone from videocall agora with flutter

I'm creating an app for video or voice call with flutter for Android / iOS. And I want to enable someone to kick another from a call. Is there anyone who knows how? any idea?
There are lots of functions in RtcEngine() and I don't know which one would remove another users.
There's a couple of ways that I can think of to do this:
RTM (new name: Signalling)
Using RTM, you could send a message to the user you want to kick, which reacts to logic on the device that then restricts it from rejoining the room. For example, send a plain text message such as "kicked_from:channel-id-here", or a json string if you want to add more complex messages that are decoded by your application:
"{\"action\":\"kick\",\"channel-id\",\"reason\":\"abuse\"}"
This is then saved into a map for example, which then is checked whenever they try to rejoin a channel.
RTM can be found here.
Via Token Server
When kicking someone from your room, you could send a message to your token server with a specific user's ID.
The token server could then revoke that token from joining the channel, resulting in them then leaving the channel. You'd have to then add some logic to either the token server or the client to prevent that user to request a new token and rejoining.

Firebase sms auto fill not working after app published to play store

looking for some help with the auto-fill OTP function for my app while using Firebase authentication service. Auto fill functionality works fine in test app as sms has the hash code. But when I publish the app on Google Playstore, the hash code in the OTP authentication sms is replaced by the app name, and hence the sms auto fill stops working as it requires the hash code. Will be great if someone has come across this problem and can help with some solution or workaround.
What's is the workaround to this
I faced the same issue and mine was due to the app name too long to contain the hash-code. Below are few work around:
You need to make sure the message you receive contains the hash of your app. Below is the right format :
123456 is your verification code for %APP_NAME%.
xyz_hascode_123
If your SMS does not contain the hashCode at the end, you might have to shorten your app name to less than 16 characters.
If your app is already published on Google Play, the name in the SMS will be the same as the one in the GooglePlayStore.
If you changed the name to 15 characters and the error still persists, you might have to wait for at least 24hours for the change to reflect on Firebase.
If after all the above it's still not resolved, please check if your receiver is well configured in the code.
Check out the new GooglePlay policy on app names: Common app names violations

Intermittent NotificationHub delivery failures with a NotificationSystemError: "InvalidToken"

I am running into an issue with NotificationHubs where occasionally notifications silently fail to get delivered to an iOS client.
My Notification Hub is setup to use token authentication with APNS (as opposed to the legacy certificate authentication).
I updated my notification hub pricing tier to standard so I could get some more information about it. Most of the time (over 95%) notifications go through correctly. I added logging to track the NotificationId of each push notification that was queued with Notification Hubs. Then, when I was alerted of a failure, I went and looked up the details for that specific notification via the following method:
var details = await notificationHub.GetNotificationOutcomeDetailsAsync("<notification id>");
Inspecting the details I noticed that while the State was "Completed" (meaning NotificationHubs had received and processed the operation) the PnsErrorDetailsUri had a non-null value, indicating there was an issue delivering the notification:
Navigating to the value of the PnsErrorDetailsUri in a browser caused the following file to be downloaded:
In here, I noticed that the NotificationSystemError says there was an "InvalidToken". This token seems like it should be related to some "under the covers" communication between Azure and APNS. It is definitely NOT due to the device token registered in NotificationHubs being invalid. I verified that the registrationId was still in notification hubs, and that it pointed to the correct device. In addition, grabbing the raw NotificationBody from the details and re-submitting it with the same tag causes the new notification to be delivered successfully.
Does anyone know what the InvalidToken may be referring to, or what could be the cause of these intermittent NotificationHub delivery failures?
UPDATE:
I have found mention of the different NotificationSystemErrors here, one of them being my InvalidToken error. However, I can't find a description of what the actual causes of these errors are.
I never really got a definitive answer why the error was happening, but I appear to have been able to resolve my issue.
We have 2 separate notification namespace/hub, one for apple production notifications and one for the apple sandbox notifications. We have a switch in place so devices register with the correct hub. I investigated all of our registrations, and they all looked to be in the correct location.
However, during this inspection I noticed that many devices had a large number of registrations. Each of these registrations had the SAME apple PNS identifier (which was a valid token), but it seemed odd to me that there were dozens (in one case hundreds) of the same PNS token registered. Each RegistrationID was the same, except it has a hyphenated incremented number after it (for instance, 1231231231235396312-6910179870480973035-1, 1231231231235396312-6910179870480973035-2, 1231231231235396312-6910179870480973035-3, etc.). It looks like each time I call NotificationHubClient.CreateAppleNativeRegistrationAsync, it is adding a new entry without de-duping. Clearing out these duplicate items seems to have resolved the issue I was encountering. Seems like NotificationHubs was getting confused sometimes with too many registrations being linked to a device.
I ended up adding some code on my end to attempt to filter out duplicates for the time being. However, I would expect that NotificationHubs should be handling this for me...

Get suggested invitees failed due to error code: 3

I'm trying to run App Invites demo on a kitkat device but it returns
Get suggested invitees failed due to error code: 3
and soon after
Create invitations failed to error code: 3
What kind of error is it? Where i can find an error list?
In my experience, this happens when the SHA-1 signature of your app is not compatible with the Android API key specified in the Google Developer Console
If you don't care which app invites you, then you might want to consider removing app/signature restrictions. Otherwise, simply add them.
Log onto Firebase Console: https://console.firebase.google.com
You will need to click on the "Add Fingerprint" button and then add on your SHA1 key. You do not need to redownload your google-services.json, you just need to add the SHA1 key.
Try sending an app invite from your app. It will now work.

Registration Process in XMPP Chat for iPhone

I am implementing a XMPP client for my iPhone App, I ahve completed all the things in (Chatting with other users , showing presence of other users , etc.)
But the one thing for which I am stuck is that , I am unable to get the new user registered from my App. I am using following snippet,
if ([appDelegate.xmppStream supportsInBandRegistration])
[appDelegate.xmppStream registerWithPassword:txt_Password.text error:nil];
But for this, supportsInBandRegistration method always returns NO and the registerWithPassword: method is never called.
Please provide some help regarding the same.
What server are you using? Some servers support in-band registration even thought they don't send the correct stream:feature according to XEP-0077. Most of them should give the feature in the disco results however.
In other words, try commenting out your if ([appDelegate.xmppStream supportsInBandRegistration]) and see if it works. If so, you'll need to complain either to your library developer or to your server developer or both.