Silent Remote Notification - App Killed status iOS 10 - ios

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

Related

iOS - Read the push notification once Received

I have 4 scenario
When the app is not Launched
Given the app was not Launched or Killed
When the push notification receive
And opened the app without tapping the notification
Then the app should capture the notification.
When the app is running in foreground
Given the app running in foreground
When the push notification receive
Then the app should capture the notification.
When the app is running in background
Given the app is running in background
When the push notification receive
And opened the app without tapping the notification
Then the app should capture the notification.
When the app is not Launched and cleared the notification
Given the app is not Launched or Killed
When the push notification receive
And user cleared the notification
And opened the app
Then the app should capture the notification.
The first 3 scenario works fine with the following code
The last scenario is not worked When the app is not Launched and cleared the notification
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { requests in
for request in requests {
self.setNotification(userInfo: request.request.content.userInfo as NSDictionary)
}
})
}
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
setNotification(userInfo: userInfo as NSDictionary)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
setNotification(userInfo: userInfo as NSDictionary)
}
According to your query
When the app is not Launched and cleared the notification
Given the app is not Launched or Killed When the post notification
receive And user cleared the notification And opened the app Then the
app should capture the notification.
This is not possible for a Normal Push notification unless the user interacts with that notification. You may want to try Silent notifications, these are not shown in the UI but the control reaches the app and you can use the data/payload from there in your code.
When user clears the notification from bar, there is no way to fetch that information.
You could also try to add the same information that is being sent in the push within an API and call it once the user opens the app.
This link deals with all the detail involved. According to your implementation, you can try a combination of both.

Push Notification not received while app is in foreground using firebase [duplicate]

I have a strange case. My swift ios app is connected to Cloudkit. If the app is NOT running (background state), I receive my notifications badge and alert just fine, every time!
If the app is running, no notifications are received! I know it is not hitting the remote because I do this:
1. Adding a breakpoint to the didReceiveRemoteNotification event
2. Running xcode in a plugged iphone
3. NSLog("detected didReceiveRemoteNotification"), so final code look like this
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
NSLog("detected didReceiveRemoteNotification")
}
I know the error is not coming from cloudkit or from APNS because I do receive alert banner and badge when the phone is in the background state.
Can you guide me to set this up properly for the Foreground state!?
I am running ios v9.3
UPDATE #1
I think the wording of the documentation is poor. It clearly says that both run on the foreground, which is what I cared about; nevertheless, the fix is more accurate than the documentation!
Unlike the application:didReceiveRemoteNotification: method, which is
called only when your app is running in the foreground, the system
calls this method when your app is running in the foreground or
background.
You've implemented the wrong method. Implement:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)
As the docs explain:
Unlike the application:didReceiveRemoteNotification: method, ... the system calls this method when your app is running in the foreground or background.

iOS - How can we set notification badge counter using FCM when the app is in background?

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.

Firebase push notification not working in background and app is inactive in swift 3.0

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.

getting silent push notification

I am trying to receive silent push notification when the app is totally off, but I'm not getting the push, what am I missing?
I added in split: Required background modes -> App downloads content in response to push notifications
I implement in the AppDelagate:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
completionHandler(UIBackgroundFetchResult.NewData);
JLToast.makeText("background").show()}
I send a push:
aps
{
content-available: 1
}
When the app is in background, I get the silent push notification,
but when the app is out of background (totally shot down),
I don't get the push.
What is missing?
As far as I know, silent push notification won't work in case the app is forced quit (by user). Consider 2 cases:
Force quit (by user, removing app from running apps list): app won't get notifications
Not force quit (Eg: when user restarts the phone, the app will be closed but it's not considered as being forced quit by user): the app will be launched in background mode and receive notifications

Resources