Is that possible to call API to send data to the server while getting silent push-notification in iOS? Any help will be appreciated.
Thanks in advance
Is that possible to call API to send data to the server while getting silent push-notification in iOS? Any help will be appreciated.
Thanks in advance
It is possible to make an API call after receiving a silent push.However, it does not work if the app is killed by the user. If that is a problem, please see this answer
If that is not the case, here is how to do it. You need to enable 'Background Fetch' and 'Remote Notifications' from Background Modes on Application Capabilities screen on XCode.
Then, add this application(_:didReceiveRemoteNotification:fetchCompletionHandler:) method into your AppDelegate.You can make your API call inside this method.
Ex:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
apiCall(fetchCompletionHandler: completionHandler)
}
func apiCall(fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void){
//Make call here
completionHandler(UIBackgroundFetchResult.noData)
}