Reputation: 91
Can we make a service call from the client side when a push notification is delivered or dismissed when the app is not active?
Also does APNS give any information on whether the notification is delivered at an individual level and is there any api we can use to query the delivery status report?
Upvotes: 3
Views: 4241
Reputation: 4977
Yes you can detect delivery of remote notification if you send the content-available
flag to 1
in the aps
dictionary. If you set the key, application:didReceiveRemoteNotification:fetchCompletionHandler:
method of the AppDelegate is called.
Also, from iOS 10 onwards, you can also detect dismissal of remote notifications. For that you need to implement UserNotifications Framework.
You need to perform the below steps for the same:
Use iOS 10 APIs to register the categories for remote notifications.
You need to check [[UNUserNotificaionCenter currentNotificationCenter] setNotificationCategories]
method for the same. See https://developer.apple.com/documentation/usernotifications/unusernotificationcenter
iOS 10 introduces a new class called UNNotificationCategory
for encapsulating a category instance. You need to set the CustomDismissAction
on the category instance to be able to receive the dismiss callback.
See https://developer.apple.com/documentation/usernotifications/unnotificationcategory
UNUserNotificationCenterDelegate
protocol with the implementation of userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:
method. This method will receive the callback to the dismiss action provided you perform the above steps.See https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate
Set your delegate to the UserNotificationCenter - [[UNUserNotificaionCenter currentNotificationCenter].delegate = your_delegate_implementation
CustomDismissAction
property in the payload. {
"aps": {
"alert": "joetheman",
"sound": "default",
"category": "my-custom-dismiss-action-category",
"content-available":1
},
"message": "Some custom message for your app",
"id": 1234
}
Upvotes: 3
Reputation: 247
Yes you can make a service call from the ios app when a notification is received when app is not active. Do this in:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
<#code#>
}
yes you can add additional key value pair in your push notification payload.
{
"aps": {
"alert": "joetheman",
"sound": "default"
},
"message": "Some custom message for your app",
"id": 1234
}
Upvotes: 0