All my code is in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; _locationMgr = [[CLLocationManager alloc] init]; [_locationMgr setDelegate:self]; if([_locationMgr respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) [_locationMgr setAllowsBackgroundLocationUpdates:YES]; CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus]; if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) { NSLog(@"relaunching because of significant location change - restarting SLC"); [_locationMgr startMonitoringSignificantLocationChanges]; } else { if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) { NSLog(@"launching with authorization to always use location - starting SLC"); [_locationMgr startMonitoringSignificantLocationChanges]; } else { NSLog(@"launching with no authorization to always use location - requesting authorization"); if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)]) [_locationMgr requestAlwaysAuthorization]; } } if([userdefaults objectForKey:@"pfuser"] == nil) { NSLog(@"in delegate signup"); SignUpController *signup = [[SignUpController alloc] init]; [self.window setRootViewController:signup]; } else { ViewController *map = [[ViewController alloc] init]; [self.window setRootViewController:map]; } [self.window makeKeyAndVisible]; return YES; } - (void)startSignificantChangeUpdates { deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"START" message:@"startSignificantChangeUpdates called" preferredStyle:UIAlertControllerStyleAlert]; [deviceNotFoundAlertController addAction:deviceNotFoundAlert];
None of the warnings occur, it looks like delegate methods are not being called.
UPDATE
Now I have:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; deviceNotFoundAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; ... }
When I test the application, I open it at home and then close it, so that when I leave my house, it should send a warning (or 3) at some point, but I do not receive a warning from any of delegate methods (where I posted the warnings).
I just got an idea, maybe I need to display warnings from the main UIViewController , and not AppDelegate ?
Perhaps thatβs why I donβt see any warnings: How to add UIAlertController to the application delegate (obj-c)
UPDATE
Here's how I now make warnings:
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"START" message:@"startSignificantChangeUpdates called" preferredStyle:UIAlertControllerStyleAlert]; [deviceNotFoundAlertController addAction:deviceNotFoundAlert]; alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; alertWindow.rootViewController = [[UIViewController alloc] init]; alertWindow.windowLevel = UIWindowLevelAlert + 1; [alertWindow makeKeyAndVisible]; [alertWindow.rootViewController presentViewController:deviceNotFoundAlertController animated:YES completion:nil];
UPDATE
Warnings did not seem to be a problem; a warning in startSignificantChangeUpdates never appears. Should it appear once when I'm at 500 m from its original location?
UPDATE
Can someone help me figure this out?
The methods of your delegate object are called from the thread in which you started the corresponding location services. This thread itself should have an active loop cycle, like the one found in the main thread of your applications.
UPDATE
I think I understood what was said above, and I have it now - I will test tomorrow.
... if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) { NSLog(@"relaunching because of significant location change - restarting SLC"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [_locationMgr startMonitoringSignificantLocationChanges]; }); } else { if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) { NSLog(@"launching with authorization to always use location - starting SLC"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [_locationMgr startMonitoringSignificantLocationChanges]; }); } else { NSLog(@"launching with no authorization to always use location - requesting authorization"); if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)]) [_locationMgr requestAlwaysAuthorization]; } } ...
I think the code starts the location services in its thread. One thing that I noticed already is that when I exit the application, the place in the upper right corner leaves. I just upgraded to iOS 10. In iOS 9, the location indicator in the upper right corner will remain there, but it will only be a black outline when the application does not work. It may just be something that they changed using iOS 10, or now, because I upgraded to 10, something else is not working now. Or is this what happens when location services start in their thread. From here: Initial iOS background thread
UPDATE
Maybe I'm misusing this thread, but, as I said, now that when I close the application, location services are ending. When I did this without a stream, the location service pointer remained in the upper right corner, like an outline.
UPDATE
I read that the service should be running in the main thread - so now I have:
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus]; NSLog(@"launching with no authorization to always use location - requesting authorization"); if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)]) { [_locationMgr requestAlwaysAuthorization]; } if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) { NSLog(@"relaunching because of significant location change - restarting SLC"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [_locationMgr startMonitoringSignificantLocationChanges]; }); } else if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) { NSLog(@"launching with authorization to always use location - starting SLC"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [_locationMgr startMonitoringSignificantLocationChanges]; }); } else {
The right arrow does not appear when the application is closed, is it something new for iOS 10 where they no longer show?
UPDATE
I accidentally deleted: _locationMgr = [[CLLocationManager alloc] init]; I inserted, and now the arrow is always there, today is going to test.
UPDATE
I tested it, but there were no warnings.