Is it possible to access the user's location on a widget?
I used the new iOS 8 API
[locationManager requestWhenInUseAuthorization];
and I added to the info.plist file the key
NSLocationWhenInUseDescription
however, when I request the location access, an alert should appear, but it doesn't happen.
Are there some not declared limitations on iOS today extensions?
As I found out, didUpdateLocations: delegate method doesn't work in today extension. So, to get location use locationManager.location.
Along with requesting authorization, you must also explicitly ask your location manager to start updating locations.
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
The key NSLocationWhenInUseDescription is wrong, therefore the Alert doesn't come up.
Change it to NSLocationWhenInUseUsageDescription and it should work.
For all keys you can refer to this:
https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
The authorization dialog does not pop up in extensions. Your app, which should be in the same App Group (in capabilities)
Related
I currently have my app setup to request location services always, using [locationManager requestAlwaysAuthorization]; and NSLocationAlwaysUsageDescription
This works fine, however I would like to give the option of using location services only while using the app like in the screenshot below.
I have tried adding NSLocationWhenInUseUsageDescription however this overides he always request and only gives the alert for while in use, any ideas on who to give both options in settings?
First ask the user using your own dialog with two options - always / when using the app. Then call appropriate permission request according to the user's choice.
Either:
[locationManager requestAlwaysAuthorization];
or:
[locationManager requestWhenInUseAuthorization];
having both in plist is valid so that's not a problem. Depends on when you actually request it in the code.
It will be slightly tricky to maintain though, so a good code structure is crucial.
The built in iOS alert will only allows for one level of permission and it will only ask the user once. The assumption is that most apps will only need one or the other. In any case, if you want to have both options show up in the Settings, you must ask for Always permission.
More importantly though:
The Always setting is really only to be used by apps that require background location updates. So unless your app requires it, you shouldn't be asking for it. Also, using background location mode will cause your app to be more heavily scrutinized during the app review process.
I have an app and I want to add some location based features to it. It supports both iOS 7 and 8, but I'm having some issues.
I want to request the permission for location only when the user taps a certain button on a certain viewController. The issue is that the permission request appears as soon as the app launches. To be more precise, between ViewWillAppear and ViewDidAppear functions of the first viewController.
What I have tried previously:
having the NSLocationWhenInUseUsageDescription key in the plist (for iOS8).
In terms of code:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
Removing the plist key -> this caused the pop up in iOS8 not to appear anymore, but it still does in iOS7
At the moment every single bit of code related to CoreLocation is commented out and I still do get the dialog asking me for permissions (iOS7 only)
I don't know what else I could possibly try, so any bit of help is much appreciated
That's just how iOS 7 (and before) works. You're not in charge of the authorization dialog: the system is. You can't make it appear; the system, seeing that you are using Core Location, presents it on your behalf. That is exactly the sort of thing that iOS 8 changes. All you can do in iOS 7 is look to see whether location services are turned on and whether your app is authorized.
Ok, I discovered the issue.
It turns out that a third party app is requesting permissions as soon as the app opens.
Thank you for all the answers.
when i am trying to get user location in iOS-8
iam getting this error
Trying to start MapKit location updates without prompting for location authorization. Must call
-[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
I have implemented:if(IS_OS_8_OR_LATER) {
[self.Mylocation requestWhenInUseAuthorization];
[self.Mylocation requestAlwaysAuthorization];
}
iam getting device location as 0.00, 0.00
please help me
In your Supporting Files folder, there should be a file called "your bundle identifier-Info.plist".
Depending on which type of location authorisation you are using (when in use or always) will determine what plist property you will need to add.
If you are using "always" usage, you will need to add the following identifier: NSLocationAlwaysUsageDescription, then add a descriptive string as to why you need to use the location.
If you want to only access the location when the app is in use, you need to add the following property:NSLocationWhenInUseDescription and again, add a relevant description string.
I just became aware of a new privacy option for Location Service in iOS 8 which allows the user to select "When app in use" as privacy option.
My application needs to go back to iOS 7, and I can't figure out how to make this option available for my application. Currently it just says "Always/Never"
I am not doing anything special in the code. Location Services are started using
startUpdatingLocation
when in the foreground, and
startMonitoringSignificantLocationChanges
when in the background.
I also tried implementing
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
to no avail.
Any ideas?
With iOS 8 you must add a new value to your plist, either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription. If you want a specific message to show when the alert is displayed to the user, you can set the string as the value to the location key.
Also you must add this code to actually ask the user the permission, switch out the function with whichever key you used in your plist.
#pragma message ("iOS 8 Support for location updating")
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]){
[self.locationManager requestWhenInUseAuthorization];
}
More information https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/
Suppose in the starting the location services are off in the default settings page. I have a button in the app to turn on the location services if first time I click on that it shows the default alert to change the settings to turn on
locationmanager = [[CLLocationManager alloc]init];
[locationmanager setDelegate:self];
[locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationmanager startUpdatingLocation];
It is working fine two times. but if it got third time location services are in off condition and click on on button it doesn't show any alert. I am unable to know the CLLocation behavior. May b its not a good question to ask but still I want to clear this concept. if anyone has some idea then please help me out.
Thank You.
Here's what Apple documentation says:
In addition to hardware not being available, the user has the option of denying an application’s access to location service data. During its initial uses by an application, the Core Location framework prompts the user to confirm that using the location service is acceptable. If the user denies the request, the CLLocationManager object reports an appropriate error to its delegate during future requests. You can also check the application’s explicit authorization status using the authorizationStatus method.
So the alert could or could not appear, based on authorizationStatus.