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.
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 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"
}
I know there are a lot of questions related to this subject, but after searching I found out that they all say that if the app is closed then the only way is to fetch the notification again from the server once the app is opened or if the app is opened from the notification then you can handle it in didFinishWithLaunch but using WhatsApp, this is not the case...
I tried sending a message to phone B (which had whatsapp closed), Phone B received the notification. Then I turned off the internet on Phone B and opened the app and still received the chat message.
Can anyone guide me on how to do this?
Probably you should use one of background modes - "remote-notification".
After enabling it, you can send push with payload like
{
"alert": "",
"badge": "0",
"content-available": 1,
"sound": ""
}
if you specify content-available key equal 1, iOS will wake your app and call application:didReceiveRemoteNotification:fetchCompletionHandler: in app delegate and you have some time to proceed push and prepare app (like download this new message to device). Here is Apple docs link with info about push payloads.
However please be aware that this push delivering is not guaranteed. Apple tells
(Newsstand apps are guaranteed to be able to receive at least one push with this key per 24-hour window.)
In our experience you likely receive it most of the time, but not always. For example app delegate callback will not be called if user swiped to close your app.
Also you need to finish execution in 30 seconds or less and call the block in handler parameter (you can check discussion section of method documentation for more details)
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'm testing out Windows Phone 7.5 push notifications. I have got the 3 different push types working fine (Toast, Tile and Raw) and am able to send messages from unit tests and a web application without any problems and receive them in my WP application. I want the ability to add extra properties to the push notification and the Raw push type does this perfectly for me and I can add custom key/value pairs or anything else to the push message and extract it on the phone app. I have just found out however that it only works if the application is running and my unit tests fail (suppressed notification status is received in unit test) when the phone application is not running (checked documentation which confirms this too). Is there anyway to add extra properties (key/values) to toast or tile messages or some way I can use raw in another way ? Toast notifications seem limited to a title property and an actual message property but I need to add additional data.
Just wondering if anyone had any suggestions / workarounds ?
The general practice I use is to initially send a raw notification to the device with phone-usable data embedded in the message. If my application is currently running then I can process the contents of the raw message and immediately make use of it on the phone. However if the application is not currently running on the phone you will receive notification from the push servers that the message could not be delievered. If I receive this response I send out a Toast / Tile notification.
With Toast notifications the only parametrisation you have access to is the URI that will launch the application. This is specified with the wp:param node of the message. Eg.
<wp:Notification xmlns:wp="WPNotification">
<wp:Toast>
<wp:Text1>Toast Title</wp:Text1>
<wp:Text2>Toast sub title</wp:Text2>
<wp:Param>/MainPage.xaml?LaunchedFrom=A%20Toast%20Notification</wp:Param>
</wp:Toast>
</wp:Notification>
If the user taps on this toast notification your application will launch and navigate to MainPage.xaml. You can access the querystring passed in via the NavigationContext.QueryString.
Note: The wp:Param node can only be sent to Mango (and up) devices. Additionally the entire contents must be less than 256 characters or you'll receive a PushErrorTypeMessageBadContent error. (Thanks to Ritch Melton for pointing this out). More info available from the Sending Push Notifications for Windows Phone page on MSDN.
As you've discovered, the Microsoft Push Notification Service is very strict in what types of messages you can send and receive. The intent of these push notifications is to provide simple push updates and not large amounts of data. The flexible Raw type seems like it would fit the bill until you discover that:
You can use a raw notification to send information to your application. If your application is not currently running, the raw notification is discarded on the Microsoft Push Notification Service and is not delivered to the device.
However, if you send a toast notification to your application, when the user clicks on the toast the application is started. When your application starts, you should check a service and retrieve the data you are trying to send from a web-service or other remote mechanism.