iOS 8 MkMapKit cannot Get Users Location - ios

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.

Related

Apple Binary Rejected (2.16)

My app requires users current location to show him direction to a particular location in google map
Below is the code to show location on web view-
[self.getDirectionsWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude,self.projectLatitude,self.projectLongitude]]]];
The app declares support for location in .plist by using NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];
Apple rejected the app with following reason
2.16 Details
Your app declares support for location in the UIBackgroundModes key in
your Info.plist file but still does not declare any features that
require persistent location. Apps that declare support for location in
the UIBackgroundModes key in your Info.plist file must have features
that require persistent location.
Specifically, we noticed that the Directions feature does not require
persistent location information, since it does not include
turn-by-turn navigation.
Any help will be appreciated, Thanks in Advance.
You just remove the location support from UIBackgroundModes key in info.plist
As you must only use UIBackgroundModes for location when you want to fetch location when your app is in background.
In your app declaration of NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription is enough.
Based on:
My app requires users current location to show him direction to a particular location in google map.
NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
we noticed that the Directions feature does not require persistent location information, since it does not include turn-by-turn navigation
It looks like they're stating you shouldn't need location information unless the app is actually active. Since the location information is used to show the user the direction they need to head in, you should be able to simply adjust (with a little latency of course) when your app comes to the fore.
From Apple's documentation:
UIBackgroundModes (Array - iOS) specifies that the app provides specific background services and must be allowed to continue running while in the background.
These keys should be used sparingly and only by apps providing the indicated services. Where alternatives for running in the background exist, those alternatives should be used instead.
For example, apps can use the significant location change interface to receive location events instead of registering as a background location app.
That'd be my analysis though it's equally likely that the reviewer just had an argument with their significant other that morning, and is just being capricious :-) Nah, just joking, but it does sometimes seem to outsiders that the decisions they make are, shall we say, less than perfectly consistent.
It's is not necessary to request the background mode to request the user's current location.
I would recommend to use NSLocationWhenInUseUsageDescription if you don't need to use the user's location in background. Users are more inclined to deny the user location authorization when they see NSLocationAlwaysUsageDescription because they think that reduce the device's battery

different behaviour for current location latitude and longitude in iOS7 to IOS8

Using xamarin for current location currentLocation example
I used the above Link for getting current location latitude and longitude.
In IOS 7 before upgrade to IOS 8 Its shows my current location latitude and longitude on both simulator and device.(Its looks strange for me in simulator for getting current location latitude and longitude).
After upgrade to iOS 8 and run same code it give
In simulator:(Turn on wifi no sim card location service App always.)
Result:
latitude = 37.785834.
longitude = -122.406517.
On Device IPhone5c (Turn on wifi no sim card location service App always.)
Result:
latitude = 37.785834.
longitude = -122.406517.
(But I expected my current location latitude and longitude )
After upgrade it does not ask, that application like use the Your Current Location GPS. an Alert message with YES, NO options.
How to get my current location latitude and longitude?
You need to request permission explicitly from iOS 8.0 onwards. The steps to do so:
Update your Info.plist file. Insert a new key: either NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys and write the custom message that will be displayed when your app requests the permission.
It is a must to have either of these keys in your plist file otherwise the permission request won't be displayed! If you don't want to show a custom explanation text in the alertview, leave the key's value string empty, but you still must have the key present in the Info.plist file!
Before you start tracking, check that you are on iOS8 then send either RequestAlwaysAuthorization or RequestWhenInUseAuthorization from the CLLocationManager instance. Example:
var locationManager = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
locationManager.RequestAlwaysAuthorization();
}
In this case, use the NSLocationAlwaysUsageDescription key in your Info.plist file. Please note, Xamarin Studio does not currently offer you this key automatically from the dropdown list, you have to enter / copy-paste this key manually there.
When using the iOS simulator you need to set the custom location for the simulator hardware. Go to Debug, select location, custom location and then set the preferred co-ordinates.
Add In LocationManger.cs file for method LocationManager
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
this.locMgr.RequestAlwaysAuthorization();
}
After change
public LocationManager ()
{
this.locMgr = new CLLocationManager();
LocationUpdated += PrintLocation;
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
this.locMgr.RequestAlwaysAuthorization();
}
}
Add Info Plist manually NSLocationAlwaysUsageDescription empty string.
Then clean the build and run the application. Its shows my current location latitude and longtidu.
I tried above solutions but that did not work. Problem is when you are targeting IOS >= 9.0 then Location manager change some permission variables, which are supposed to mention explicitly in info.pList.
<key>NSLocationWhenInUseUsageDescription</key>
<string>Why you need Location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Why you need Location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Why you need Location</string>
<key>NSLocationWhileInUsage</key>
<string>Why you need Location</string>
use these four keys if you want to target all versions .. before and after 9.0.
Also note that this line means whether user is in foreground or background use locations (apple discourage this because it has potential of privacy) check documentation here
[locationManager requestAlwaysAuthorization];
whereas this means,
[locationManager requestWhenInUseAuthorization];
Only use when app is in foreground check documentation here

How to enable "When app in use" in CLLocationManager in iOS 8

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/

Access the user's location on Today Extension

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)

didUpdateToLocation alert called only twice

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.

Resources