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

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!

Related

Azure NotificationHubs how do I get the devicetoken from an iPhone

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.

Hide push notification for particular message

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

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

Sinch APN shouldSendPushNotifications never called

I can´t make Apple Push Notifications work in development mode. The shouldSendPushNotifications method is never called on the source device when the target device is in background mode. I have uploaded my APN development certificate in the Sinch Dashboard and instant messaging works if both devices are in foreground mode. I have a valid device token which I´m using for my own Push Messages. Here is my code:
sinCli = Sinch.clientWithApplicationKey("XXXX", applicationSecret: "XXXX", environmentHost: "sandbox.sinch.com", userId: sinchUserId)
sinCli.delegate = self
sinCli.setSupportMessaging(true)
if let deviceToken = defaults.dataForKey(Globals.KEY_APN_DEVICE_TOKEN)
{
sinCli.setSupportPushNotifications(true)
sinCli.registerPushNotificationDeviceToken(deviceToken, type: SINPushTypeRemote, apsEnvironment: SINAPSEnvironment.Development)
sinCli.setPushNotificationDisplayName("MyApp")
}
sinCli.start()
sinCli.startListeningOnActiveConnection()
sinCli.messageClient().delegate = self
did I forget something?
I think I need to see your swift wrapper, but it almost looks like you are setting up the client for push (not managed), and then registring the token for managed push.
When using managed push (when you upload to cert to us) shouldSendPush is never called, because Sinch takes care of the pushing, you should just get a push. What you do need is to have a push delegate https://www.sinch.com/tutorials/ios-managed-push/

Can I tell if a user opened my app by tapping on a toast notification?

Is there anyway to get the context that an app has been opened? ie. Has the user pressed on a received toast notification or have they clicked on the application tile? My reasoning is that I will send the user a toast notification (eg. 1 new message for you!). If they tap on the toast notification I would like the app to open at an inbox like screen as opposed to my home screen.
Add some parameter to Toast or Tile Url. For example, /Views/MainPage.xaml?from=toast that tells you that user tap a toast instead of just launch your app from a menu. It's called Deep Links

Resources