IOS, even when the application is completed

I try to update the location of users even when the application is completed. I added maps and background → Location update to my .plist, and I set a local notification that will fire when the location is updated. But no one fired him. I have this in AppDelegat.h:

@interface AppDelegate : UIResponder <CLLocationManagerDelegate>{
    CLLocationManager *locationManager;
}

and in AppDelegate.m

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager requestAlwaysAuthorization];
    [locationManager startMonitoringSignificantLocationChanges];
}

    - (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations {

 UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.repeatInterval = NSDayCalendarUnit;
[notification setAlertBody:@"Location update!"];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]];
[notification setTimeZone:[NSTimeZone  defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }

I tested this code on a simulator with a Freeway drive as a place and it does not work.


EDIT

If I put the code under applicationDidEnterBackground, the authorization request will close the second one that he opened, because I use didFinishLaunchingWithOptions. I know that this is 24 hours location tracking because there is a GPS symbol there, even when the application is completed.


EDIT 2

. . , ():)

+2
1

, CLLocationManagerDelegate:

-(void)locationManager:(CLLocationManager *)manager 
        didUpdateToLocation:(CLLocation *)newLocation 
        fromLocation:(CLLocation *)oldLocation { 
}

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations {
}
+1

Source: https://habr.com/ru/post/1613354/


All Articles