An appropriate way to get the user's location (also in a killed state) for the hyperlocal application

Requirement - I am creating a hyperlocal application that will provide offers to the user depending on their location. When in the application I can get its current location and show offers accordingly, but now I need to send a push notification to the user depending on his location. Therefore, I want to find out the user's location and send offers based on their location.

I read an Apple document for Location Service with a significant change , but then this answer says that it will not work after the application is killed.

I also read about User Location Tracking , but this did not work for me correctly. I have not received more than 5 updates in the background.

My current code in viewDidLoad is

 if (self.locationManager == nil) { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self; self.locationManager.allowsBackgroundLocationUpdates = true; self.locationManager.pausesLocationUpdatesAutomatically = false; if ([CLLocationManager authorizationStatus] != AVAuthorizationStatusAuthorized) { [self.locationManager requestAlwaysAuthorization]; } } [self.locationManager startUpdatingLocation]; 

And my delegate method looks like this:

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { // Get updated data according to location } else { // Send location to server } } 

Features of my applications And my plist is enter image description here enter image description here

Please suggest a suitable method, I can live with an accuracy of about 1 km.

Other approaches -

  • Can I get the user's location in "Background - Background Fetch" fetchNewDataWithCompletionHandler: :?

  • Can I get the user's location using the Silent Push application:didReceiveRemoteNotification:fetchCompletionHandler: ? ): Impossible according to this answer

+7
ios objective-c swift cllocationmanager
source share
2 answers

So your question is basically ā€œHow can I get around Apple’s specially designed user experience for people who want to close my application?ā€ The answer to this question is: "No, if you want to stay within the rules for the AppStore."

Listen, if the user decides to terminate your application (i.e. they scroll up and exit the task manager), this whole goal is for your application to stop something . Apple designed this so that people can quickly turn off exactly the behavior that you seem to want to implement. I don’t quite understand why you would like to get around this. I agree that this interaction is a bit unclear (in the end, users can also allow / deny the application’s right to receive location updates in the background in the Settings application), but this determines the iOS interaction.

If I understand you correctly, you were able to correctly configure the background location modes so that your application can receive location updates, even if it is not in the foreground (that is, in the background or paused, in the latter situation, iOS will wake it so you can process updates locations and, for example, send a local notification to inform the user). This is as good as it gets.

Oh, and don't be afraid to reboot the device. Yes, after the reboot, your application does not technically work, but since the last time the user clearly did not kill him, iOS treats him as if he was in suspend mode, IIRC, so you will still receive significant location updates and will be able to respond normally, ( More generally, people often seem to think that the actual state of the application process reflects the state of the application, as defined in the documentation, and / or that the application is shown in the task manager, is related to this. ).


Edit after your comment asked me a question about choosing a background:

Sorry, perhaps this was not entirely clear. I specifically did not answer this question, because after the user intentionally dismissed your application, you should not, as explained, ā€œdeceiveā€ your intention. Because of this, silent push notifications will not work.

I don’t know if the background selection will be reset in the same way (maybe, but I haven’t tried it), but I think this will not help you either, even if it still works (which I doubt Apple will probably be difficult on this occasion). I also never tried (re) triggering location updates in this method, so I can’t say if it even works (as soon as the completion handler is called the system, it will most likely pause your application, at least, and I'm not sure if this "resets" the user killed the application flag, which the system apparently uses to determine which application wakes up and delivers location updates).

application:performFetchWithCompletionHandler: (since it is fully called) the heuristic-based OS will be called, it tries to be smart on this. Since this method is designed to retrieve some data from the backend that does not provide push notifications, the times it calls at all can be very limited, as explained in the documentation . The actual mechanism that decides when the OS call is a black box and it is a gamble to try to trick it when called when you need it. It can be very likely that this will happen in a few hours. Think of the following scenario:

  • Your application works fine in background location modes (did I understand correctly that you installed it successfully? See here and here )
  • The user manually kills your application. For the sake of this argument, suppose that the system does not restart the system later to allow it to fetch background
  • Since other applications are running on the system, and at the moment the user has only a boundary connection, the OS decides that this is a bad time to initiate background sampling (I just assume that these factors play a role, since it is a black box, but to me it seems reasonable). Your user walks around a few more, bypassing several places that interest you.
  • After two hours, the user is already in a completely different area, your application starts the OS again and receives a call to application:performFetchWithCompletionHandler: You run location updates again (suppose it even works, and the system does not immediately terminate the application again, that is, even after fake background extraction ensures that the location is updated in the background). You have missed several locations, but, nevertheless, the application now processes new ones. All your logic is mostly confused because you did not plan to have so many missing location updates ...
  • (Optional: after a while, your user understands that your application seems to be doing something, even though it has stopped it (for example, they notice a battery leak). They will delete your application and leave a one-time review. ..)
  • (Optional 2, the worst case scenario: as soon as the apple realizes that after updating the user’s application, it’s possible to reinitialize the background updates, they just close the loop in the iOS update and your application returns there we started ...)

For the record: I don’t advocate any design decisions made by an apple, damn it, I know that it is confusing to wrap my head and how can I take the position of ā€œsave battery and user intention under any circumstancesā€ do one for better background tracking. I simply point out that they are in control here and trying to fondle around any specific interaction paradigms that they establish on the platform, probably not a good idea.

That says it all, I'm afraid that "the user has stopped the application, now I do not receive any location updates" - this is just what you need to live with. Why would this be a problem for you if you didn't say anything about the background location modes you were missing? The only (dubious) scenario that I could imagine was a kind of tracker application, possibly given on devices handed out to delivery service employees or something like that. If this is so (and put aside ethics for such things, in some countries that are even illegal, mind you ...), I must say that iOS is simply not the right platform for this.

+2
source share

Hi, just create a UILocalNotification , setting it with your data and most important for the notification that will be triggered when you type Region add the Region property, see the docs

Hope this helps

-2
source share

All Articles