Does APNS understand UTF-8 encoded payload - android

I am using Apns-Node.js for sending push notifications to my iOS device and GCM-Node.js for my Android device.
Currently I have a payload sent to APNS which contains special characters like "ü" in the payload. This gets displayed in the same format and doesn't get truncated or modified by APNS for any reason.
But my Android app has this issue where GCM truncates the special character in the payload unless it is encoded using URL encoding.
"türken" -> gets truncated to "trken" unless it is encoded like "t%C3%BCrken" in GCM only
In an effort to keep both platforms uniform, can I send the encrypted payload to APNS as well? And if I do so, will APNS understand the UTF-8 format and send the payload with special character to the device? My expectation is that APNS should understand the encoded format "t%C3%BCrken" and send "türken" to the device. Will this work?

Based on your explanation, APNS properly supports UTF-8. This means it will deliver the payload as is.
This means if you send "t%C3%BCrken", then the client will receive "t%C3%BCrken", but your iOS client applications can easily remove the percent encoding by using removingPercentEncoding.

Related

Decoding payload msg going through lorawan multitech conduit gateway

I managed to get a node to communicate to an android app. The message goes from the node to the gateway. Using node-red the gateway publishes the message to an mqtt broker and I subscribe to the right topic to receive that message on my android app.
Only problem I have now is that I never realized that the msg was encoded and I'm quite lost now. I receive an array of bytes on the app side and I'm not sure what is the next step I have to take to be able to read that message.
Thanks for the help!
You are actually receiving bytes from Node-Red. You could either convert the received bytes into String on your Android or modify your lora input node's data type from Bytes to UTF-8.
I have a function to decode it:
var x = Buffer.from(msg.payload.raw,"base64").toString()
msg.Decrypted = parseFloat(x)
return msg;
In this Instructable i explained how to decode Lora messages in node red
https://www.instructables.com/id/Lora-Temperature-Dashboard/
On a MultiTech Conduit, the message is base64 encoded by the internals of the MTC, then published to the internal mqtt broker at lora//up, so you need to base64 decode it, then do whatever you need to with it. You can use the built in mosquitto applications to subscribe to this topic, or any other mqtt client (paho libraries, etc)

Single GCM Push sent to multiple devices with different GCM Id's

We use GCM messaging to send remote commands to device. We have one particular client who uses the same model of devices from one manufacturer and with has 5.1 OS.
Our client registration process is pretty standard, that is once the client logs-in, it updates the GCM-Id to server and on server we have some commands that can be sent to the registered devices and internally it uses the registration id.
We are observing that even if the remote command is sent to one of the devices, it is being delivered to all these devices. The GCM Id on all these devices is different.
This does not happen with other devices (or we have not seen it yet)
If we use FCM Diagnostics and verify the lifecycle of message using the GCM-Ids of these devices we see that the same message ID has been delivered to all these devices.
We made sure that there is no ghost or random delivery from our backend, we verified backend logs and added extra logging as well.
Request for tips or hints, if anybody else saw such an issue earlier.
Try see this git on line 57, he uses json to sent a single message to multiples registration ids.
Example json content:
{
"data":
{
"from": "my_name",
"time": "0:56:23"
},
"registration_ids": ["id_1", "id_2", "id_3", "id_4"]
}
Lucas is correct in his example, the registration_ids is a parameter that specifies a list of devices (registration tokens, or IDs) receiving a multicast message. It can contain at least 1 and at most 1000 registration tokens.
Note: registration_ids are only for multicast messaging, not for
single recipients. Multicast messages (sending to more than 1
registration tokens) are allowed using HTTP JSON format only.
For more information, check this documentation.

Mosquitto publish message format to android app

I am working on a IoT project where i'm using mosquitto broker to get messages to my android app. But when i receive the published messages on my app, they appear to be in a weird format. how can i get the data in correct format. Do i need to change something in mosquitto configuration.
The data sent: "hello"
Received on app: [B#2df51a89
this is what i use to get the text in onMessageReceived(topic,message)
message.getPayload().toString();
Any help is appreciated.
[UPDATE] - When i publish data FROM mobile app, the data is received perfectly at the subscriber. Vice versa doesn't work.
You've printed out the object representation of the byte array (message payload). The correct thing to have done is to create a new String from the byte array using a known encoding (probably UTF8)
String payload = new String(message.getPayload(), "utf8")
Then print the payload String

Getting Bad Request (400) on Azure Notification Hub's "Test Send"

I'm trying to send the following payload to a specific device (which is why I'm using the registration_ids) via Test Send on Azure's Notification Hub, but I'm getting a bad request error.
{
"registration_ids" : ["2670873167838193734-9582072870486547213-1"],
"data":{"message":"Hello World!"},
}
I'm not sure why since I checked the formatting and it looked fine to me based on other sources I saw.
Does anyone have an idea on what's happening?
EDIT:
Here's how I eventually managed to send a notification to a specific user:
on the client side (Java), I replaced the line
hub.register(regid)
with
hub.register(regid,"myTag")
Where "myTag" can be any other string tag you want. That way you can enter the word myTag in the 'Send to Tag' on Azure's Notification Hub and verify that you received the notification on your device.
Also, if you want to send the notification from the server side (C#), you'll need to add this header to your http request:
request.Headers.Add("ServiceBusNotification-Tags", "myTag");
Hope this helps anyone.
registration_id would not be part of the payload (see https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx request body) although it is part of GCM's payload. To send to a specific device, you will need to tag that device with an id of sorts (e.g. registration_ids) and send to the tag "{registration_id}".
This is due to registration_ids field in the payload. Notification Hub does allow passing the registration_ids in the payload. Notification Hub internally substitute the registration id (before sending to GCM/FCM) based on selected devices.
https://msdn.microsoft.com/en-us/library/azure/dn530749.aspx
Thanks,
Sateesh

Android GCM push notification for localization application

I have a single android application, which supports for 7 countries(Localization and Internationalization). The application functionality and language changed based on the device locale.
I need to implement the GCM push notifications for this application.
Requirement:
Is it possible to send the push notification in 7 different languages with single GCM account.
Is there any way to display the push notification in their device local language.
You can either take the approach suggested by Ascorbin, or implement something similar to what Apple have in their push notifications:
Your server can send a GCM message with a parameter that is a key to a message. Yout Android App will have to contain for each possible key the strings that should be displayed for it in each of the 7 languages (using multiple copies of strings.xml). Then the GCM reciever in your app will get the key from the server and get the resource string that matches it (it will automatically get the string that matched the locale of the device). This way you don't have to worry about localization in your server. The downside of this approach is that all your messages have to be predefined in your app.
You can also add parameters to the message key like Apple do.
For example, the server sends a key = "NEW_MAIL_FROM" and param1 = "John". The app finds a string resource for that key (lets assume the device used English locale) - "You have a message from {0}" - and replaces the param with John, displaying the message "You have a message from John". A device with a differennt locale will show a message in a different language.
You can implement that server-side, after GCM registration with the send of token, send also the device locale. And then notify users instantly with a localized message.
Payload is something "sort" its not a good idea to pass through it so much information.
On the other hand if you have fixed messages you can use:
private void handleMessage(Intent intent) {
// server sent key-value pairs
String name_of_resource = intent.getExtra("message_id");
int id = getResources().getIdentifier(name_of_resource, "string", getPackageName());
if (id != 0) {
String text = getString(id); // the text to display
// generates a system notification to display here
}
}
see http://developer.android.com/google/gcm/gcm.html#received_data for handling received data.
When the devices register at your server, let them send the Locale. So you can have locale groups of devices and send the messages in according languages.
You can easily localize your GCM notification using title_loc_key and body_loc_key. These keys listed in official GCM docs.
More details can be found here.
Send a GCM Push from server (without any language specific data).
In response to the push, the client makes a REST api call to the server with it's language as a Query parameter.
The server fetches appropriate language's text and send back to the client on real time.

Categories

Resources