I am using core location framework. I am checking Authorization status (kCLAuthorizationStatusDenied/kCLAuthorizationStatusRestricted
) in user-defined method.
The noticeable point is this method is being called in case of the normal flow of execution (there is no problem).
But in the case of when the user quit/terminated the app and again relaunch it (by tapping on app icon). In this case, before and after methods will be called and only this(Authorization()
) method won't call.
Why did this abrupt behaviour happen?
Can anybody tell me execution flow in Objective C?
In .h file -
@property (strong, nonatomic) LocationTracker * locationTracker;
In .m file -
[self userTrialMethodBefore];
[self.locationTracker startLocationTracking];
[self userTrialMethodAfter];
- (void)userTrialMethodBefore
{
NSLog(@"This method gets called before ");
}
- (void)startLocationTracking
{
NSString *responeParam = @"";
if ([CLLocationManager locationServicesEnabled] == NO)
{
responeParam = @"Disabled location";
}
else
{
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if(authorizationStatus == kCLAuthorizationStatusDenied || authorizationStatus == kCLAuthorizationStatusRestricted)
{
responeParam = @"Unauthorize location";
}
else
{
responeParam = @"Authorize location";
CLLocationManager *locationManager = [LocationTracker sharedLocationManager];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
if (SystemVersion > 9.2)
{
[locationManager setAllowsBackgroundLocationUpdates:YES];
locationManager.pausesLocationUpdatesAutomatically = false;
}
[locationManager startUpdatingLocation];
}
}
}
- (void)userTrialMethodAfter
{
NSLog(@"This method gets called after ");
}
[Note: I am using Xcode 9.2, iOS 11.2.2 device, objective c language]
Somewhere when you allocate the CLLocationManager
you need also to call the requestWhenInUseAuthorization
like this:
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
and why you are not using self.locationTracker
to startUpdatingLocation
but instead retrieve a sharedLocationManager
?