Which activityType is better for using? - cllocationmanager

I have an app that can be used for driving, skiing, walking, train, etc. Which activityType should be used? Will CLActivityTypeAutomotiveNavigation cover all usecases?
Code is to cater for iOS 8 and 9 - (have a niggling doubt that the respondsToSelector should be removed):
if ([locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
locationManager.activityType = CLActivityTypeAutomotiveNavigation;
}
if ([locationManager respondsToSelector:#selector(pausesLocationUpdatesAutomatically)])
{
locationManager.pausesLocationUpdatesAutomatically = YES;
}

Related

i can't get user location when i'm in the building with iOS 11

i'm developing an iOS application using CLLocationManager to get current user location.
When i'm out of the building it's work well but i'm come to in the building delgate of CLLocationManager always return 0 to me.
Can i get exactly the location when i'm in the building?
I have checked on google maps and apple maps it's aways work well
Plz help me.
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLLocationAccuracyBest;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startMonitoringSignificantLocationChanges];
if(IS_OS_8_OR_LATER) {
[locationManager requestWhenInUseAuthorization];
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
If you are inside a building then you are unlikely to be able to receive a GPS signal. Unless your building is a significant public place (airport, shopping mall) that has been added to Apple's indoor mapping then you will not get a location while indoors.

Significant change location not trigger in iOS 10

Significant change location service not trigger on iPhone 7 plus but it work on other devices. please help ... .
I have tried following code
[appDelegate.locationManager stopUpdatingLocation];
appDelegate.locationManager=nil;
appDelegate.locationManager=[[CLLocationManager alloc]init];
if(IS_OS_8_OR_LATER)
{
[appDelegate.locationManager requestAlwaysAuthorization];
}
if ([appDelegate.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[appDelegate.locationManager requestAlwaysAuthorization];
//flag=1;
}
appDelegate.locationManager.delegate = appDelegate.self;
if(IS_OS_9_OR_LATER) {
appDelegate.locationManager.allowsBackgroundLocationUpdates=YES;
}
//appDelegate.locationManager
appDelegate.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
appDelegate.locationManager.distanceFilter = 200;
//locationManager.activityType=CLActivityTypeOtherNavigation;
appDelegate.locationManager.pausesLocationUpdatesAutomatically=NO;
[appDelegate.locationManager startMonitoringSignificantLocationChanges];
This Code not works on iPhone 7 plus but works on other devices and iOS 10 OS.

Do not show alert each time when startUpdatelocation

I am working on location app where I need to get the location. When I come on the particular ViewController & location is off it gives alert showing that switch on the location which is fine.But the problem is once I say cancel & next time call [locationManager startUpdatingLocation]; it will not show me alert to switch on location.
- (void)getCurrentLocation {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
if ([locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
}
Note - I have done changes in plist to
NSLocationAlwaysUsageDescription set to The XYZ app would like to use
your current location
Sadly this is by design. Its so an app developer can't harass the user with endless requests.
What you have to do is check the [CLLocationManager authorizationStatus] and if its kCLAuthorizationStatusDenied then display a message that the user needs to go into their settings app and enable locations for your app.
You should handle the other authorized states as well. See the list in the CLLocationManager Documentation - CLAuthorizationStatus
Check the status before startUpdatingLocation. i.e.
if([CLLocationManager locationServicesEnabled])
{
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
NSLog(#"Add your alert here");
}
else
{
[locationManager startUpdatingLocation];
}
}
else
{
NSLog(#"Add your alert here");
}

Drop pin in Mapview issue in iOS 8

if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 500;
[locationManager startUpdatingLocation];
[locationManager stopUpdatingLocation];
[locationManager startUpdatingLocation];
}
Above code works fine till iOS 8.
in ios 8 drop pin is not displaying in mapview .
Yes ios target is ios 7 and higher.
I also try several method but not working.
Any solutions ?
I've encountered this before. There's a location authorization issue due to core location manager changes in iOS8. Try adding this below code before calling startUpdatingLocation:
if ([self._locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[self._locationManager requestWhenInUseAuthorization];
}
self.mapView.showsUserLocation = YES; //optional
Prior to this, please make sure you add one or both of the following keys to your Info.plist file:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription

didUpdateUserLocation not firing inside view with background updates

I have an app that uses background location updates, it needs to constantly track the devices position regardless if the app is in the foreground or background. I have the background tracking setup in the app delegate.
In the front end I have a single UIViewController with a working mapkit view all the CCLocationManager code triggers without error but didUpdateUserLocation is never fired within the custom UIViewController class.
Background location tracking is working with absolutely no problems.
Here is the code i'm using in viewDidLoad
[self.mapView setShowsUserLocation:YES];
[self.mapView setShowsPointsOfInterest:YES];
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager setDelegate:self];
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
NSString *error;
if (![CLLocationManager locationServicesEnabled]) {error = #"Error message";}
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusRestricted || status == kCLAuthorizationStatusDenied) {error = #"Error message";}
if (error) {NSLog(error);}
else
{
status = [CLLocationManager authorizationStatus];
self.locationManager.pausesLocationUpdatesAutomatically = NO;
self.locationManager.activityType = CLActivityTypeAutomotiveNavigation;
[self.locationManager stopMonitoringSignificantLocationChanges];
[self.locationManager startUpdatingLocation];
}
Any help would be appreciated
Thanks
You need to check below details:
Testing this on simulator?? didUpdateLocations must be tested on real device.
Make sure that you specified the NSLocationAlwaysUsageDescription string or else the app won't present the authorization message, and you won't be authorized.
Have you implemented locationManager:didFailWithError:? did you got any error?
Have you implemented locationManager:didChangeAuthorizationStatus:? Are you getting this called with a successful authorization status?
I worked out the problem finally.
Turns out even if you're using the location stuff in Schema and Xcode you still need to set it in the Simulator via Debug > Location
Hopefully this helps someone else.
and now, with iOS 9, the following needs to be included for any update;
if ([ locationManager respondsToSelector:#selector(requestWhenInUseAuthorization )])
{
locationManager.allowsBackgroundLocationUpdates = YES;
}
Else background updates will be impaired.

Resources