I'm using method for background refresh, works when app is active. But in background mode (app isn't killed), can't make Api request to take new data from server.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> ()) {
case .active:
// works
...
completionHandler(.newData)
case .background:
// doesn't refresh / make api request
completionHandler(.newData)
}
Also remote notifications are enabled on background mode Capabilities.
Any solution for refreshing/ fetching data in background mode?
Maybe the following question, and the answer on that question can help you since it is a similar problem, maybe even a duplicate.
Related
I am new to Swift and Firebase, I implemented the FCM perfectly, I am processing the data inside each notification and display it. However, I had a problem: Instead of tapping the pop-out windows of notification, I later tapped the APP ICON and the notification wasn't got processed and no data was updated on my app page.
Can someone please tell me how to fix this? My intuition is to write something in AppDelegate, but I had already had the same process in func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) and application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) as the other function has. Thank you!
I later tapped the APP ICON and the notification wasn't got processed and no data was updated on my app page.
That's expected. If your app has 10 notifications received and you tapped on the app icon, how is your suppose to know which notification it needs to process?
I am trying to set the notification badge counter in my app when the app is in background/terminated?
But I'm not getting any clue how should I set the badge counter .
In foreground it's fine I can update notification badge counter.
Now I tried to use the background service by adding content_availbe key in firebase payload and invoking the following method:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
But my this method is not invoked although i've included content_available key to 1 in my payload.
Has anyone been able to set the notification badge counter when the app is in background with fcm messages?
**NOTE: ** I am concerned about updating push notification counter from app not from the server. Can we update app badge counter from background execution ??
Any help.
I am integrating Silent Remote notification in my application, all is working fine. But the issue is when my app is in killed state or not running state then no application delegate methods are getting triggered.
When I see in device log I can see:
"Springboard : High Priority Push: - App killed".
Can anybody please help me out.
I have implemented
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Swift.Void)
When app is in background and foreground state then above method is getting trigger.
I have enabled back ground fetch and Remote notification in the capabilities
Note:
I am sending silent push notification through terminal like this :
apn push <device_token> --certificate <path_of_pem_file> --payload '{"aps":{"content-available":1}}'
Thanks in advance
I am implemented on FCM in swift 3.0. FCM notification is working if my application is in foreground properly, but notification is not getting if application is in background or in inactive state. I have implemented all the steps provided by firebase, below function getting called only app is active.
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void)
Please suggest if there is any better way to do this.
I am looking for a way for my IOS application to exchange information with my server once a remote notification has been received but before the user has taken any action and decided whether he should open the application or not.
In my App Delegate, I have tried something like
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
NSLog("%# remote notification received ", __FUNCTION__)
MyServerJSONRPCRequest.getMyStuff();
completionHandler(UIBackgroundFetchResult.NewData)
}
When the remote notification is received I definitely gets into this but the actual request is never sent to my server, it is sent only if I actually open the app from the application.
Possible explanation : has it anything to do with the fact the request is asynchronous?
2nd possible explanation : I do not have any clue about the right usage of UIBacgkroundFetchResult