I'm trying to set a title using Bluemix push notification when the unlocked style is in Alert mode, and seems like there is an option in apple documentation to set the Title according to Payload Keys
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1, but I cannot see that option in Bluemix push rest API doc https://mobile.ng.bluemix.net/imfpushrestapidocs/#!/messages/post_apps_applicationId_messages
And I cannot use silent push notification because it's not working when the app is killed by the user and it's not running --references BlueMix Push Notification - support for Apple localized alert messages And more reference https://forums.developer.apple.com/thread/31403
So I just can see that the title's tied to my application name, is there any way to change it not using silent push notification?
I appreciate your answers
As you saw in the Apple Documentation, you can set the title of an alert by setting the parameter title in the UIAlertController.
e.g.
#IBAction func buttonTapped(sender: AnyObject) {
let alertController = UIAlertController(title: "iOScreator", message:
"Hello, world!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
See this article for more information on that.
Now it looks like your other question is asking if you can set a title parameter from your actual push notification for the alert.
This isn't supported out of the box, but you could send it as an Additional Payload parameter and parse this parameter when you receive the push notification from your device.
So you would:
Send the notification with the title in the Additional Payload
Receive the notification from the device and get the title from it
Set the title in the UIAlertController
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.
Is it possible to hide push notification for particular push notification message. We have push notification for location update. It will keep coming and from that data, we have to update in map. We have to hide push notification for particular push message(Here I mean location update push message).
You must use silent notification for such message.
Configuring silent notifications
To support silent remote notifications, add the remote-notification value to the UIBackgroundModes array in your Info.plist file. To learn more about this array, see UIBackgroundModes.
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
Sending a Silent Notification
The aps dictionary can also contain the content-available property. The content-available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about out the next time they open your app.
For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don’t follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user.
Pass the empty completionHandler([]) to hide remote notification:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent
notification: UNNotification,
withCompletionHandler completionHandler:
#escaping (UNNotificationPresentationOptions) ->
Void)
{
let userInfo:[AnyHashable:Any] = notification.request.content.userInfo
print("\(userInfo)")
completionHandler([])
}
We want to make a native application using Apple push notification. We want to make a native application using Apple push notification. The problem is we want to custom the system notification when users hover on it. We notice that Skype can show the Reply button when you hover on its notification .
Does anyone know how to create a notification like Skype does?
We'd also like to be able to make a couple of other modifications as well:
Show a different notification on hover.
Show a different notification on hover, preferably with a custom view, possibly including an image or webview?
Thanks.
Update:
I found that Skype don't use APNS to push new message (when Skype doesn't run, you won't see the notification when a new message arrive). The notification on the screen is a local notification. So, in my case which using remote notification, I ignore the alert key of remote notification payload and when the app receives a remote notification, it will remove this notification from Notification Center and push a new local notification. Here is the code:
func application(application: NSApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println(userInfo)
// remove the remote one
let deliveredNotifications = NSUserNotificationCenter.defaultUserNotificationCenter().deliveredNotifications
if let lastRemoteNotif = deliveredNotifications.last as? NSUserNotification {
NSUserNotificationCenter.defaultUserNotificationCenter().removeDeliveredNotification(lastRemoteNotif)
}
// push another local notification
let localNotif = NSUserNotification()
localNotif.title = ""
localNotif.deliveryDate = NSDate()
localNotif.title = "CeillingNinja"
localNotif.subtitle = "This is local notification"
localNotif.informativeText = "Some text"
localNotif.contentImage = NSImage(named: "Status")
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(localNotif)
}
But when the app isn't running, user will see an empty notification in Notification Center. I still stuck at that point!
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.
I am planning out a Mac OS X (Lion) application and wanted to ask some questions about APNs.
First off: Can you send APNs to a Lion Application that is something other than a Badge or Alert? That is, can you perhaps send a key/value pair or some such data to the end-point application that it can use to determine what action to take? Pretty sure I could do this in iOS land but not for Mac OS X
Will the application that receives the event be able to do so - even if it's in the background?
Lastly, does the application need to have a UI? i.e. can I write a back-ground only application that can be the end-point for the notification?
What I really am trying to work out is if I can leverage APNs on Lion as general purpose mechanism for alerting my application to do something or if it's purely for delivering UI alerts?
You can only register for badge alerts (NSRemoteNotificationTypeBadge) but you can send the same payload type as in iOS and the Mac app will receive it. So far I've only managed to get running and background apps to receive the notification, but the docs say:
Mac OS X Note: Because the only notification type supported for
non-running applications is icon-badging
So it seems like non-running apps should be able to get the notification, but I haven't figured that out yet.
Here's my app receiving a notification in the background:
2012-02-13 18:00:39.531 TestPush[25580:707] Received Push Alert: TESTING
2012-02-13 18:00:39.532 TestPush[25580:707] Received Push Badge: 10
2012-02-13 18:00:44.153 TestPush[25580:707] applicationDidResignActive
2012-02-13 18:00:57.233 TestPush[25580:707] remote notification: {
"_" = "n7dBZFYpEeGiNBT+tdMfCA";
aps = {
alert = TESTING;
badge = 10;
};
}
Here's a custom payload (key/value pairs that you mentioned):
2012-02-13 18:23:44.665 TestPush[25958:707] remote notification: {
"_" = "zsUPTFYsEeGiNBT+tdMfCA";
acme1 = bar;
acme2 = 42;
aps = {
alert = "You got your emails.";
badge = 9;
sound = "bingbong.aiff";
};
}
2012-02-13 18:23:44.666 TestPush[25958:707] Received Push Alert: You got your emails.
2012-02-13 18:23:44.666 TestPush[25958:707] Received Push Sound: bingbong.aiff
2012-02-13 18:23:44.667 TestPush[25958:707] Received Push Badge: 9
2012-02-13 18:23:44.667 TestPush[25958:707] Received cust1: bar
2012-02-13 18:23:44.668 TestPush[25958:707] Received cust2: 42
Not sure about the UI part, I wouldn't have thought you need a UI though.
Also check out this sample code from Apple PushyMac.