Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 11    Views: 69

AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
04/06/16 09:54 AM (8 years ago)

Location Map and driving directions - iOS

In an app I am working on, I use the std Location Map plugin to show a point on a map and to launch driving direction from the map pin. The problem is that my device location is not being passed to the map. I've had this working in the past, but it is no longer enough. THe app is not prompting me to allow for location services to be enabled when it starts. I saw Smugs post here https://www.buzztouch.com/forum/thread.php?tid=DF37E99C6D78AE0D929E2BA I saw Susan's recent thread https://www.buzztouch.com/forum/thread.php?tid=15F05E707AB1146DC3FA7A6 I already had he plist entry and then I applied code changes to BT_screen_map.m but it made no difference.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
04/07/16 06:19 PM (8 years ago)
I noticed an odd occurrence once while playing with a location based app... check in your settings for the 'app' privacy settings... I noticed if I installed the app, and said 'ok' for location updates... and later 'removed' the app, and reinstalled, the settings are not the same, and I had to go in and manually 'accept' location updates (in settings; it never asked from the app again). Could yours be exhibiting similar behavior? Cheers! -- Smug
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/07/16 11:42 PM (8 years ago)
Hmm, my app isn't in the list. Which tally's with not asking for permission on 1st start. I don't know why, that's probably where to focus some attention.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/08/16 03:08 AM (8 years ago)
I started a fresh app and followed the instrucions in your PDF Smug. My basic test is to show my iPhone location on a map. I put the change you outlined into BT_Core>BT_locationManager. The app still does not prompt, but I now find that the app is now listed in iPhone settings>privacy>Location Services settings. None of the permissions are defined, but it picks up the 'we use location services responsibly' explanation text from my apps plist (which is now standard in BT 3 app downloads). I set permission to 'while using', restarted my app, still no prompt to ask about allowing locations, but the map shows my iphone location. So some good progress there. To test your theory about installing and removing, I then renamed the app and tried again, which added a second app to my iPhone. it still refuses to prompt to allow on first load and so the permissions don't get set by the app. It seems to me that something else needs to be done as well.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/08/16 03:14 AM (8 years ago)
Oh, and I just noticed that when you delete an app completely from your iPhone, any entries for that app in iPhone settings>privacy>Location Services settings disappear too.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/08/16 06:47 AM (8 years ago)
I've worked out the prompting to use location services is tied in some way to core settings in the control panel. If you want the app to prompt to use location services, I found you must have 'Turn on GPS - yes start gps on launch enabled' in core settings. I noticed when I start my app now, that it prompts the first time and GPS goes on immediately, then off again 45 seconds later. It goes on again when I go into the location map screen, unfortunately it stays on when I go back to the home screen, which could be a bit of a battery drainer.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
04/08/16 08:21 AM (8 years ago)
Try making sure the settings are for 'NSLocationWhenInUseUsageDescription' and not 'NSLocationAlwaysUsageDescription'. That (if I understand correctly, which may be suspect, lol!) should release GPS control from the app while it is inactive. Cheers! -- Smug you may or may not want to consider adding: [appDelegate.rootLocationMonitor stopLocationUpdates]; to something like, viewWillDissappear, etc... just to 'shut it off' while leaving.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/08/16 01:32 PM (8 years ago)
Hi Smug, app is using NSLocationWhenInUseUsageDescription already. What I think I need is to switch off gps when exiting a location map screen within the app. Is that possible?
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/11/16 04:35 AM (8 years ago)
Here is the code I use that goes into BT_locationManager.m (in the BT_Core folder) to allow me to be able to set the permission for location services. I think that this is pretty generic to anything that wants to use location services while the app is being used, unless you need location services to run when the app is in the background, as per your post above Smug. This code goes in at line 60 and replaces the existing method -(void)startLocationUpdates{
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/11/16 04:35 AM (8 years ago)
//start location updates -(void)startLocationUpdates{ [BT_debugger showIt:self message:[NSString stringWithFormat:@"startLocationUpdates %@", @""]]; @try { //if we have not already done this.. if(self.locationManager == nil){ //init location manager self.locationManager = [[CLLocationManager alloc] init]; [self.locationManager setDelegate:self]; if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { // Without this test app will crash with "unknown selector" on iOS 7 or below [self.locationManager requestWhenInUseAuthorization]; // ask for permission to use location for ios 8 and above } [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; // [self.locationManager setDesiredAccuracy:kCLLocationAccuracyThreeKilometers]; [self.locationManager startUpdatingLocation]; } else { if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { // Without this test app will crash with "unknown selector" on iOS 7 or below [self.locationManager requestWhenInUseAuthorization]; // ask for permission to use location for ios 8 and above } [self.locationManager startUpdatingLocation]; } }@catch (NSException * e) { }@finally { } }
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/11/16 04:36 AM (8 years ago)
What happens now is that when the app starts, it fires up GPS for a short period of time then the the gps turns off again. If I go into a location map screen, the gps comes back on. If I leave the location map screen, the gps stays on. If I put the app into the background, gps turns itself off after a short time. If I then bring the app into the foreground, gps is on and stays on, without me navgating to the location map screen. What I would like is for the gps to switch off when I am not in a location map screen. Is that possible?
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/11/16 04:56 AM (8 years ago)
To confirm, the app will only prompt to allow for location if 'Turn on GPS - yes start gps on launch enabled' ia previously enabled in core settings. Also, my original problem of being able to usedevice location set the start point for driving instructions does not seem to work in iOS , but does for iOS 8.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.