Show a custom notification at the moment the app update finishes? - ios

I need to notify the user about new features of my app as soon as the app update finishes and the app is not in the foreground (i.e., it is terminated or is in the background). How do I achieve this? This scenario will happen if the app was already installed and auto-updates were on.
I achieved this on Android using MY_PACKAGE_REPLACED broadcast receiver. I've read about NSNotificationName in NSNotificationCenter in iOS but couldn't find an equivalent to MY_PACKAGE_REPLACED.

You cannot do this with iOS without the app running in the background Period. Even if your app is running in the background after Appstore updates the app, your app gets killed and you don't have control over it until the user launches it for the first time.
Maybe you could try sending a silent push notification to the app to see if it responds and try to get the current app version.

Related

Does firebase notification call 'application:didReceiveRemoteNotification:' after force close an iOS app?

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. But I want to send push notification after force an app to close on iPhone, iPad, or iPod touch. It is important update my apps data silently. I have already tried silent push notification in background mode. But it's not work in quite mode.
Will iOS perform background tasks after the user has force-quit the app?
If perform, fiarebase push notification build in method application:didReceiveRemoteNotification: execute?
Please reply anyone...
No, apps that were force-closed via the task manager are not normally restarted when push notifications are received. This is documented here:
In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system. When password protection is enabled on the device, the system does not launch an app in the background before the user first unlocks the device

Can't make a network call from background notification after app force-quit and phone restart

I am using background notifications in my app. And I use it to make a small call to our server after each notification. Tested on iPhone 5/6 and iOS 11
In those cases I am able to call the server to mark my notification as received :
the app is in foreground
the app is in background
I just reboot my device
But sometimes users kill the app and then I can not call my server, that is a normal behaviour of background notification.
BUT, from the documentation :
However, the system does not automatically launch your app if the user
has force-quit it. In that situation, the user must relaunch your app
or restart the device before the system attempts to launch your app
automatically again.
Source : https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application
So if I am correct, if I force quit the app and then restart my device I should be able to make a network call again after phone restart.
This is my issue, it does not work. After a force quit of my app and a phone restart the notification is displayed on the screen of the phone but the network call is not done.
Do you have the same issue ? Do you know a solution ?
Your application has to be in the multitasking stack to make a call to server when notification is received. That is, application has to opened atleast once after the reboot to meet your expectation.

Background fetch is not working after killing the app

I'm trying to get data from url with background fetch. My func tries to get data and if there is a new data, it sends local notification. Background fetch works after about 10 - 20 minutes when i minimize the app. But when i kill the app (double click home button and close app) it doesn't work. I waited about 1 hour but it didn't work. I am using background service in android and it is working successfully. Is there any way to get data from url and send local notification when app is closed? I am using Xcode 6 and swift 1.2
The Background Fetching will NOT happen in your app after the user has killed it in the multitasking UI. This is by design.
Take a look at Apple's documentation that mentions:
Apps that support background execution may be relaunched by the system
to handle incoming events. If an app is terminated for any reason
other than the user force quitting it, the system launches the app...
and
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user. In other
cases, though, the user must launch the app explicitly or reboot the
device before the app can be launched automatically into the
background by the system.
As you noticed in the documentation, there's only 1 exception when the app will be relaunched if it was force killed: by using location services. Unfortunately this does not apply to you.
Also, you cannot detect if the app was force killed by the user. Check this StackOverflow answer.
The Background Fetching will NOT Update in your app after the user has killed app from background. it is not Possible

Will iOS launch my app into the background if it was force-quit by the user?

I am triggering a background fetch by using the content-available flag on a push notification. I have the fetch and remote-notification UIBackgroundModes enabled.
Here is the implementation I am using in my AppDelegate.m:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(#"Remote Notification Recieved");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = #"Looks like i got a notification - fetch thingy";
[application presentLocalNotificationNow:notification];
completionHandler(UIBackgroundFetchResultNewData);
}
When the app is running in the background, it works fine. (The notification is received and the app triggered the "looks like i got a notification" local notification, as the code above should do).
However, when the app is not running and a push notification is received with the content-available flag, the app is not launched and the didRecieveRemoteNotification delegate method is never called.
The WWDC Video Whats New With Multitasking (#204 from WWDC 2013) shows this:
It says that the application is "launched into background" when a push notification is received with the content-available flag.
Why is my app not launching into the background?
So the real question is:
Will iOS perform background tasks after the user has force-quit the app?
UPDATE2:
You can achieve this using the new PushKit framework, introduced in iOS 8. Though PushKit is used for VoIP. So your usage should be for VoIP related otherwise there is risk of app rejection. (See this answer).
UDPDATE1:
The documentation has been clarified for iOS8. The documentation can be read here. Here is a relevant excerpt:
Use this method to process incoming remote notifications for your app.
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. In addition, if you enabled the remote notifications
background mode, the system launches your app (or wakes it from the
suspended state) and puts it in the background state when a push
notification arrives. However, the system does not automatically
launch your app if the user has force-quit it. In that situation, the
user must relaunch your app or restart the device before the system
attempts to launch your app automatically again.
Although this was not made clear by the WWDC video, a quick search on the developer forums turned this up:
https://devforums.apple.com/message/873265#873265 (login required)
Also keep in mind that if you kill your app from the app switcher
(i.e. swiping up to kill the app) then the OS will never relaunch the
app regardless of push notification or background fetch. In this case
the user has to manually relaunch the app once and then from that
point forward the background activities will be invoked. -pmarcos
That post was by an Apple employee so I think i can trust that this information is correct.
So it looks like when the app is killed from the app switcher (by swiping up), the app will never be launched, even for scheduled background fetches.
You can change your target's launch settings in "Manage Scheme" to Wait for <app>.app to be launched manually, which allows you debug by setting a breakpoint in application: didReceiveRemoteNotification: fetchCompletionHandler: and sending the push notification to trigger the background launch.
I'm not sure it'll solve the issue, but it may assist you with debugging for now.
The answer is YES, but shouldn't use 'Background Fetch' or 'Remote notification'. PushKit is the answer you desire.
In summary, PushKit, the new framework in ios 8, is the new push notification mechanism which can silently launch your app into the background with no visual alert prompt even your app was killed by swiping out from app switcher, amazingly you even cannot see it from app switcher.
PushKit reference from Apple:
The PushKit framework provides the classes for your iOS apps to
receive pushes from remote servers. Pushes can be of one of two types:
standard and VoIP. Standard pushes can deliver notifications just as
in previous versions of iOS. VoIP pushes provide additional
functionality on top of the standard push that is needed to VoIP apps
to perform on-demand processing of the push before displaying a
notification to the user.
To deploy this new feature, please refer to this tutorial: https://zeropush.com/guide/guide-to-pushkit-and-voip - I've tested it on my device and it works as expected.
Actually if you need to test background fetch you need to enable one option in scheme:
Another way how you can test it:
Here is full information about this new feature:
http://www.objc.io/issue-5/multitasking.html
I've been trying different variants of this for days, and I thought for a day I had it re-launching the app in the background, even when the user swiped to kill, but no I can't replicate that behavior.
It's unfortunate that the behavior is quite different than before. On iOS 6, if you killed the app from the jiggling icons, it would still get re-awoken on SLC triggers. Now, if you kill by swiping, that doesn't happen.
It's a different behavior, and the user, who would continue to get useful information from our app if they had killed it on iOS 6, now will not.
We need to nudge our users to re-open the app now if they have swiped to kill it and are still expecting some of the notification behavior that we used to give them. I'm worried this won't be obvious to users when they swipe an app away. They may, after all, be basically cleaning up or wanting to rearrange the apps that are shown minimized.
This might help you
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user. In other
cases, though, the user must launch the app explicitly or reboot the
device before the app can be launched automatically into the
background by the system. When password protection is enabled on the
device, the system does not launch an app in the background before the
user first unlocks the device.
Source:
https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
For iOS13
For background pushes in iOS13, you must set below parameters:
apns-priority = 5
apns-push-type = background
//Required for WatchOS
//Highly recommended for Other platforms
The video link: https://developer.apple.com/videos/play/wwdc2019/707/

Blackberry background Push Notification using MDS

I am working on Blackberry Push Notification using MDS. I have referred the sample project HTTPPushDemo which Blackberry API has provided. I am getting pushed data successfully only when app is running. How I will get pushed notification using MDS when app is not running ?
The typical arrangement is to have two apps - the foreground app and the background app. The foreground app has all the UI elements, and it starts when the user clicks on the app icon on the device, and terminates when the user selects 'exit' This would largely be what you've written already.
The background app hides itself - no icon is present in the app switcher or on the device. This means the background app continues to run whether or not the foreground app is running. This allows you to setup the push listener, and keep it running even when your app is "not running"
Both 'apps' actually inhabit the same codebase - you differentiate them by adding a new start argument, and then in the app startup, the code checks whether it should be the foreground or background app, and behaves appropriately.

Resources