How can I know if the user has closed the application from the background - background

How can I send certain data to the database in case the user killed off the app directly from background or if the app is minimized but haven't being killed yet so it's in background, how can I do that I would be very grateful to anyone giving me this information.
i am using flutter
if ( App is being killed OR in background mode??? Just an example of what is required )
FirebaseFirestore.instance.collection("users").doc(currentUser.uid).update({
"AppStatus" : false
});

Related

WP8: Can this (PhoneApplicationService.RunningInBackground ) be used outside of location based app?

From this link below, it seems that your app can still get event when app is switched to background. But it seems it is used only for location based app. Can normal app do that? I had tried to declare ID_CAP_LOCATION but still Application_RunningInBackground not get called when switch to background.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.shell.phoneapplicationservice.runninginbackground(v=vs.105).aspx
The app doesn't execute in background, unless it is continously tracking the location.
This section lists the conditions under which the operating system
will deactivate an app running in the background....
The app stops actively tracking location. An app stops tracking location by removing event handlers for the PositionChanged and
StatusChanged events of the Geolocator class or by calling the Stop()
method of the GeoCoordinateWatcher class.
Source: Running location-tracking apps in the background for Windows Phone 8
You will find complete info of how to run apps in background here:
How to run location-tracking apps in the background for Windows Phone 8

NSURLConnection when app is in background

I'd like to know if is possible to send asynchronous connections when an app is in background. The reason for this is because I need to send the user's location (get from Core Location) to update a database in a remote server everytime the location changes, even if the app is not in foreground.
Do I have to set any permission for this? Does Apple rejects apps processing connections when app is in background?
Thanks in advance!!
iOS provides multitasking API's i.e. even if your app is in background, some of its API's can be accessed. These services are -
Local Notifications
Background Audio
Background Tasks
Background Location
So you can definitely send location updates using CoreLocation when the app is not in foreground.
This link - iOS multitasking has code to start your service when app in background. Step by step instructions
Specify location background mode
Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
In case x time is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case x is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. This does work since location is one of the three allowed types of background execution.
SOURCE - How do I get a background location update every n minutes in my iOS application?
Here, from the apple documentation (http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW47)
There are several ways to track the user’s location in the background, most of which do not actually require your app to run continuously in the background:
-The significant-change location service (Recommended)
-Foreground-only location services
-Background location services
But you cannot send request, as the only possible things to do are :
-audio
-location
-voip
-newsstand
-Accessories & blutooth connection
So I guess you could store all your location, and send it with NSURLConnection once the app goes to foreground again

How to find out user is at desktop instead of start screen or another store app UI at Windows 8

As we know, at windows 8 if user is at start screen or another store app (metro app) UI, the dialog at the desktop won't be visible to user. We are adding some toast notification capability at our application by following Sending toast notifications from desktop apps sample. I am able to get it working. However if user is already at the desktop, we don't want to send out the toast notification. So it would mean that we need to be able to detect if user is current at desktop or not. Somehow I didn't find any API by searching on internet. Could someone let me know how to do so? Thanks very much.
A toast notification can't know in what context the user is located, so this is not possible.

Long-running task performed in foreground is suspended when app enters background

When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.
Is there any way to either:
prevent an iOS app from entering the background whilst I perform my download
or continue peforming the task in the background (i.e. perform the task irrespective of whether the app is in the foreground or background)
Thanks
It really doesn't matter, if the user presses the home button it will go to background. Although you can do two things to mitigate the problem:
Use beginBackgroundTaskWithExpirationHandler, to give you a bit more time to download. Which you can read here.
Don't allow the device to become iddle, with [UIApplication sharedApplication].idleTimerDisabled = YES;. You can read more about that here.
Either way, the best thing you can do is to tell the user, that is an important download and he shouldn't quit the application.
Can't you include some or all of the content in your app bundle instead, and just download changes on first run?
I can't imagine this is a good first user experience, and it may not pass App Store review like this.
The only third party apps that are allowed to download in the background are newsstand apps loading issue content, and Apple are pretty strict about what they allow as newsstand apps.
You can't do what you want, in this situation. One way, and I think the best and only, is to resume your download when you app becomes active (returns to foreground state). Also, don't forget to register for connectivity notifications (Reachability class can be used for this purpose from this Apple sample app http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html). Good Luck!

how to delay application quit time in iphone sdk?

I want to register my app for push notification when my application terminates so i think if i delay my app quitting time it could be possible.Does someone knows how to delay application quitting time? I think this method
[self performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait];
will do my job but i don't know how to use this method if someone knows please tell.I need to send some data to a server along with registering for Push Notification when my app quits.
I can't imagine why you would want to do this. If it were even possible it would be extremely annoying for a user to tap the home button and the app to take x amount of time to shut down. This time 'x' being dependent on the server connection creates even more user headache.
Apple have the home button exit apps immediately for a reason.
If you want to register the Push Notifications like you suggest, do it while the app is running. If your worrying that they won't be properly set if the user exits prematurely... don't.
As users, we all know there are sometimes consequences of exiting a program without giving it time to save your settings.
For push notification it is better to register when the app first starts and then send the push token to your server in the background. However, if you have a good reason why you need to do the registration just as the app terminates, I believe you can do this if you are using iOS 4. iOS 4 has a new feature called "task finishing" that allows an app to stay running for a few minutes after the user closes it so that it may finish up any tasks it was in the middle of (such as saving data).