Reputation: 1509
I am developing an application (Family Safety) where one family member can request and get current location of other family member without consent of other family member . Even when the app is not running. this cannot be achieved by push notifications as Push notifications won't work when app is not running. I don't want to show user a notification when someone is requesting location. I want it to work no matter app is running or not. Please suggest me any solution to achieve this task.
PS. please don't tell me that I shouldn't get user location like this or my app will be rejected. Because I am developing this application for Family Security company and family members will first read and accept to company's policy.
Upvotes: 0
Views: 1139
Reputation: 1946
Requesting a location of a device without user intervention and that too, when the app is not running, is not possible in iOS.
The only way to get the Device location in iOS when the app is terminated, is to use Significant Location change. SLC will give location update even when the app is not running. It will just wake up the app and give the location update.
But if you want the location of the device on request, the app must be running to receive the request and process it.
Upvotes: 0
Reputation: 1003
First use requestAlwaysAuthorization
instead of requestWhenInUseAuthorization
for CLAuthorizationStatus
to access location when app is quite.
Now use
UIApplication* application = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[self locationManager] startUpdatingLocation];//call you web-api here to update location on server.
[application endBackgroundTask: background_task];
background_task = UIBackgroundTaskInvalid;
});
This will help.
Upvotes: 2