I have Azure notification hub working on Xamarin Forms for iOS and Droid to receive general push notifications. I am trying to send a POSTID in my payload and then take that ID and direct to the data behind it. My issue, I cannot seem to get the postid to read into the app. Every time I get an empty ID. The Push notification an Droid and are received, but the extra data, like postid are not.
{"aps":{"alert":"Test #03_01","postid":"8921"}}
Can someone point me to some documentation on this? How to make it work with ID/data in the push notification behind the scene.
You'll need to promote your custom data fields. At the moment, they are in the "aps" section, which is reserved for data that will be consumed by APNS or iOS. Somewhere along the line your fields are being stripped.
Here's the APNS documentation for building request payloads.
For you it should look something like:
{
"aps": {
"alert":"Test #03_01"
},
"postid":"8921"
}
Related
I am using Azure NotificationsHubs for iOS push notifications and want to get the deviceToken to register the device, along with the user, in a table through an api so I can send notifications to specific users/devices and keep track of badge counts. When not using Azure Notification Hubs.
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
print("DeviceToken: \(deviceToken)")
}
I see the documentation says:
By default, the SDK will swizzle methods to automatically intercept
calls to UIApplicationDelegate/NSApplicationDelegate for calls to
registering and intercepting push notifications, as well as
UNUserNotificationCenterDelegate methods. Note this is only available
for iOS, watchOS, and Mac Catalyst. This is not supported on macOS and
tvOS.
I'm not sure what swizzling means but I don't want to disable what I have working thus far. Is there another way within the standard implementation to get the deviceToken?
I also see this in the documentation:
To target a particular user on the backend, you can specify a tag such as $UserId:{VALUE} where VALUE is the user name you have specified, just as you can target an installation using the $InstallationId:{VALUE} tag.
But how do I get the InstallationId and is that different from the deviceId or value I use in xcrun simctl push? I expect somewhere I will need to store it on the server side and associate it with a user or something.
I read this post which states:
When you send a notification from the server, one of the paramters is the device ID.
I could do it by user only, but what if they want different notification preference for different devices?
I expect to send to a specific user on a specific device from the server you would use tags, for example:
Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null;
String userTag = "(UserId:xxxx)";
// substituting for iOS
var toast = "{\"aps\":{\"alert\":\"This is a test\"}}";
outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag);
On the client, I am setting the user id like this:
let userId = "xxxx"
MSNotificationHub.setUserId(userId);
Even without the device id part of it, I can't get the user part working. I can send a notification without any tags, but I add in the user tag and it does not work. I assumed by calling setUserId that would add a tag, based on the links above.
I use Back4App service to send push notifications. I managed to get push notifications to work, and they work from the client and from the server, but the problem is that all notifications come with the same format (title>name of the app, alert>name of the app).
I am sure I am changing the alert and the title text in the json, but still they are all sent with the app name.
This is my json table:
{
"channels": [
"TestChannel"
],
"data": {
"alert": "The Mets scored! The game is now tied 1-1.",
"title": "Mets Score!"
}
}
Here is how I call the function (using lua in corona SDK):
parse.request(parse.Push.send)
:data(pushJson)
:response(function(responseString, responseTable, errorTable)
adjustResponseString("Sending Push", responseString, responseTable, errorTable)
end)
This is my current app name "ParseTest".
Here is what the notification looks like:
https://i.snag.gy/rXQ9Ja.jpg
(This is the case when I send push notifications from both client and server.)
at the moment, I'll recommend to you work with Cloud Code Function (It works with JS SDK) and you can call it via your project app, the guides are:
What is Cloud Code function?
You can send Pushes via your JS SDK using this link.
I am trying to use Azure Notification Hubs to send push notifications to a client. I read this article which uses tags to identify each user.
https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-aspnet-backend-windows-dotnet-notify-users/
It does the work, but the number of tags is limited. I was thinking to store and use the Registration ID that the Hub returns.
Is there any way to send notifications using this ID?
Another way would be using the Channel.URI that is returned by WNS. Can this be implemented somehow?
Actually NH limits only number of tags per single registration but per hub you may have as many registrations as you need and each registration may have unique tag which you can use to route the notifications.
Also there is new Installation API for Notification Hubs which I believe fits better for you. It is still not well-documented but well-done and ready to use. Here you can find short description of how to use that API. Readme is about Java but .NET SDK has pretty much the same capabilities (in the end both call same REST API).
Keyword is TAG ! If you use any spesific tag for any registered device which is Android,IOS,Windows OS etc, you can send notification to any specific device.
To do these, you should follow below steps one by one ;
As Client side, register device using a spesific tag to selected Azure Notification Hub
Client Example for Android :
`/*you don't have to use Firebase infrastructure.
You may use other ways. It doesn't matter.*/`
String FCM_token = FirebaseInstanceId.getInstance().getToken();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString, context);
String registrationID = hub.register(FCM_token, "UniqueTagForThisDevice").getRegistrationId();
Like you see, we have used a unique tag call "UniqueTagForThisDevice" for selected Android device.
As Server Side, you should send notification using that TAG call "UniqueTagForThisDevice".
Server Example using Web API to send push selected Android device :
[HttpGet]
[Route("api/sendnotification/{deviceTag}")]
public async Task<IHttpActionResult> sendNotification(string deviceTag)
{
//deviceTag must be "UniqueTagForThisDevice" !!!
NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString("<DefaultFullSharedAccessSignature>");
var notif = "{ \"data\" : {\"message\":\"Hello Push\"}}";
NotificationOutcome outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif,deviceTag);
if (outcome != null)
{
if (!((outcome.State == NotificationOutcomeState.Abandoned) ||
(outcome.State == NotificationOutcomeState.Unknown)))
{
return Ok("Push sent successfully.");
}
}
//Push sending is failed.
return InternalServerError();
}
As last, you should call above Web API Service method using "UniqueTagForThisDevice" tag from any helper platform (Postman, Fiddler or anothers.).
Note : TAG doesn't have to be deviceToken or similar things. It just have to spesific for each devices. But I suggest you that, if you use WebAPI and it is related with Owin midlleware, you may prefer username as unique tag. I think, this is more available for application scenarios. In this way, you can carry sending notifications from unique devices to unique users ;)
That's all.
I developed an iOS 8 mobile application that successfully interfaces with Bluemix push service.
Using Bluemix to generate my push notification I supply content in the Message Text field which is delivered to my application as part of the app's structure.
Using Bluemix to generate my push notification I also supply Additional Payload, but I'm not able to see this content as part of the app's structure.
Appreciate any details on how to use the Additional Payload field, its format, and how I can access that content when processing the alert within my mobile application.
Payload is an object in userInfo at the same level as aps
Rainer
The Payload in Apple Push Notification is handled in UserInfo NSDictionary object and composed as JSON dictionary object.
Please see the following links that can provide you more information.
Apple
Handling Local and Remote Notifications
Notification Payload
I've found this post to be really helpful in getting set up, but I have yet to see the push notification come through on the iPhone on which the pass is installed.
Passkit-push-notification-not-working-with-urban-airship
I set up my app on urban airship's site pushing to Apple's development servers. I installed a pass on my phone and run the following commands which I found in the above post:
airship = urbanairship.Airship(_UrbanAirshipPassbookKey, _UrbanAirshipPassbookMasterSecret)
airship.push({'aps': {'alert': 'Go.'}}, device_tokens=tokens)
I then see confirmation of this push in the iPhone console window in Xcode.
Received push for topic pass.xxx.xxx: {
...
aps = {
banner = "Hello";
};
and the iPhone then sends its update tag back along with its pass type ID and Device Library ID to the web service. At this point the web service is supposed to send back a list of changed passes. However, I instead see the following error message:
<Warning>: Web service error for pass.mypasstype.id (http://192.168.30.209:8000): Response to 'What changed?' request included 1 serial numbers but the lastUpdated tag (2013-02-11T17:25:25) remained the same.
Does anyone know why this is happening? Do I need to actually modify a field in the pass to get the push notification to appear on the device?
The short answer to your question is yes, you do need to modify a field in the pass to get a push notification to show. This is because, unlike with app pushes, a Passbook push payload does not determine the content of the notification.
The purpose of a Passbook push message is to alert the device that the web service has a new pass with updated content. The alert text is determined solely by the new pass contents. Any content in the push payload is ignored. Apple advise a push notification with an empty JSON dictionary.
Once a push is sent, it triggers the following chain:
Device receives push and queries web service with the passTypeIdentifier and lastUpadted tag
Web service provides a list of serials for all passes with the passTypeIdentifier that have changed since the lastUpdated tag
Device receives serial(s) and requests the web service to send the new .pkpass bundle for each new pass
Web service send the new .pkpass bundle
Device receives the .pkpass bundle and checks it against the old pass for changes
If the following criteria are met, the device will display the notification provided in the changeMessage key:
The value has changed
The changeMessage contains the %# string
Id the %# string is not present, the pass will show a notification Pass Changed. If no changeMessage key is present for the changed value, no message will show.