Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will I get current location even if the app is killed or terminated ? #86

Closed
KrLikeblue opened this issue Oct 27, 2016 · 10 comments
Closed

Comments

@KrLikeblue
Copy link

KrLikeblue commented Oct 27, 2016

I want to get user current location even if the app is killed or terminated. And When user start walking, location must be updated even if the app is killed or terminated.. Is it possible ??

@KrLikeblue KrLikeblue changed the title Will I get current location even the app is killed or terminated ? Will I get current location even if the app is killed or terminated ? Oct 27, 2016
@iwasrobbed
Copy link
Contributor

iwasrobbed commented Oct 28, 2016

@KrLikeblue You can monitor for significant location changes using subscribeToSignificantLocationChangesWithBlock within this framework.

https://developer.apple.com/reference/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati

If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives.

@wholeinsoul
Copy link

Does this mean that even if I have subscribed to continuous updates using subscribeToLocationUpdatesWithBlock my app will not get notified if application terminates. To get notified after the app has been terminated, I need to subscribe using subscribeToSignificantLocationChangesWithBlock also and when didFinishLaunchingWithOptions is called with UIApplicationLaunchOptionsLocationKey, I need to subscribe again with subscribeToSignificantLocationChangesWithBlock and subscribeToLocationUpdatesWithBlock.

Can you please confirm ?
Thanks.

@iwasrobbed
Copy link
Contributor

iwasrobbed commented Mar 30, 2017

@bishtpradeep Correct. If your app is terminated, you can only get location updates using significant location changes (every ~500m or so). Once you subscribe, you won't need to resubscribe (unless you unsubscribe).

@wholeinsoul
Copy link

wholeinsoul commented Mar 30, 2017

Thank you for such a quick response.

I was not sure about the re-subscription at launch-after-termination. The README says:

Note that when the app terminates, all of your active location requests & subscriptions with INTULocationManager are canceled. Therefore, when the app launches due to a significant location change, you should immediately use INTULocationManager to set up a new subscription for significant location changes in order to receive the location information.

and then in example it re-subscribes.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // If you start monitoring significant location changes and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives.
    // Upon relaunch, you must still subscribe to significant location changes to continue receiving location events. 
    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
        INTULocationManager *locMgr = [INTULocationManager sharedInstance];
        [locMgr subscribeToSignificantLocationChangesWithBlock:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
            // This block will be executed with the details of the significant location change that triggered the background app launch,
            // and will continue to execute for any future significant location change events as well (unless canceled).
        }];
    }
    return YES;
}

@iwasrobbed
Copy link
Contributor

@bishtpradeep Apologies; it's been a while. If that's the case in the readme, then I would go that approach (re-subscribe).

@wholeinsoul
Copy link

okay. Thanks again.

@lwdupont lwdupont closed this as completed Jul 2, 2017
@mrshyi
Copy link

mrshyi commented Nov 30, 2017

Hi, @iwasrobbed thanks for the awesome lib . But in iOS11 ,maybe it is not working.

In iOS 11 startMonitoringSignificantLocationChanges working fine in background but not working if killed the app.

I am using NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription both key i added in plist. Always authorization i am getting. Even in background its working fine. but if kill the app, location update is not working.

What i have to do fix this issue? Please help on this.

@iwasrobbed
Copy link
Contributor

@mrshyi I haven't used this library in a couple of years now (and I'm not the maintainer). To be completely honest, you're probably better off just using the iOS APIs since they are fairly simple to use. Keep in mind you need to test on device and iOS 11 had a lot more privacy changes in it so I'd look around for others having issues with the significant updates.

@sheshnathiicmr
Copy link

if you are willing to use VOIP push see this link - https://www.appcaretaker.com/2018/06/05/how-to-get-iphone-ipad-current-location-even-if-app-is-terminated-not-running-in-background/

@intuit intuit deleted a comment from ipsjolly Jan 6, 2019
@kailasb
Copy link

kailasb commented Jun 11, 2020

@sheshnathiicmr link is not working. is any other option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants