Hide push notification for particular message - apple-push-notifications

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([])
}

Related

How to set Title in Alert notification using Bluemix push notification service?

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

Display the push notification ios only if it for the user saved category inside app

I have created a shopping cart IOS app where the user can save Categories for which they are interested in (saved inside app localstorage). Now, whenever the admin is adding any product, I am sending the push notification from the server.
My question is how should i handle push notification, so that when my push notification will arrive on an ios device, it will check using APN PAYLOAD that if this product is from the user saved interested categories (saved inside app localstorage) and then display the push notification to the user, else the push notification will be ignored.
Can someone please tell me how to handle this exactly??
P.S - I am aware of the Silent Push Notifications and Push Notifications in IOS, the only problem is you can use the silent push notification for some app processing but again let's say if I send a Push Notification for an added product in cart, and when the app will receive the silent push notification and after code processing how I can again display the push notification again if the push notification is for the user interested category???

How to implement advanced notification with reply button (and customisation)

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!

Handling Toast and Raw Push Notifications

My WP7 app needs to handle different types of push notification. Some of these are only relevant when the app is running but one type serves as a prompt to the user to start the app as well as needing to be handled while the app is running. Hence, when opening the push channel, my code calls BindToShellToast and registers event handlers for when both raw and toast notifications are received:
if (!_pushChannel.IsShellToastBound)
{
_pushChannel.BindToShellToast();
}
_pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(pushChannel_HttpNotificationReceived);
_pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
Looking at the certification requirements, it appears that I have to provide a user setting to allow them to enable/disable not only push notifications in general, but also specifically toast notifications. See Additional requirements for specific app types for Windows Phone (requirement 6.2.1)
Since the user could potentially enable general push notifications but disable toast notifications, it seems to me that my server would need to send both a raw and a toast notification for the type that needs to be handled when the app is not running. This would make registering for the ShellToastNotificationReceived event pointless. Is my thinking correct here?
You should store a settings on your server for each registered device naming what type of notification the user allowed.

Windows Phone 7 - Is it possible to add additional key/values to push notifications messages

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.

Resources