Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 498 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Location Services not working in iOS 8

#11
Before `[locationManager startUpdatingLocation];`, add an iOS8 location services request:

if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[locationManager requestAlwaysAuthorization];

Edit your app's `Info.plist` and add key `NSLocationAlwaysUsageDescription` with the string value that will be displayed to the user (for example, `We do our best to preserve your battery life.`)

If your app needs location services only while the app is open, replace:

`requestAlwaysAuthorization` with `requestWhenInUseAuthorization` and

`NSLocationAlwaysUsageDescription` with `NSLocationWhenInUseUsageDescription`.
Reply

#12
I was working on an app that was upgraded to iOS 8 and location services stopped working. You'll probably get and error in the Debug area like so:

`Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.`

I did the least intrusive procedure. First add `NSLocationAlwaysUsageDescription` entry to your info.plist:

![Enter image description here][1]

Notice I didn't fill out the value for this key. This still works, and I'm not concerned because this is a in house app. Also, there is already a title asking to use location services, so I didn't want to do anything redundant.

Next I created a conditional for iOS 8:

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_locationManager requestAlwaysAuthorization];
}

After this the `locationManager:didChangeAuthorizationStatus:` method is call:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus: (CLAuthorizationStatus)status
{
[self gotoCurrenLocation];
}

And now everything works fine. As always, check out the [documentation][2].

[1]:

[2]:

[To see links please register here]

Reply

#13
**One common error for Swift developers:**

First make sure you add a value to the plist for either `NSLocationWhenInUseUsageDescription ` or `NSLocationAlwaysUsageDescription`.

If you are *still* not seeing a window pop up asking for authorization, look to see if you are putting the line `var locationManager = CLLocationManager()` in your View Controller's `viewDidLoad` method. If you do, then even if you call `locationManager.requestWhenInUseAuthorization()`, nothing will show up. This is because after viewDidLoad executes, the locationManager variable is deallocated (cleared out).

The solution is to locate the line `var locationManager = CLLocationManager()` at the top of the class method.
Reply

#14

- (void)viewDidLoad
{

[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){
NSUInteger code = [CLLocationManager authorizationStatus];
if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
// choose one request according to your business.
if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){
[self.locationManager requestAlwaysAuthorization];
} else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
[self.locationManager requestWhenInUseAuthorization];
} else {
NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
}
}
}
[self.locationManager startUpdatingLocation];
}

> #pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;

if (currentLocation != nil) {
longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
}

> In iOS 8 you need to do two extra things to get location working: Add
> a key to your Info.plist and request authorization from the location
> manager asking it to start. There are two Info.plist keys for the new
> location authorization. One or both of these keys is required. If
> neither of the keys are there, you can call startUpdatingLocation but
> the location manager won’t actually start. It won’t send a failure
> message to the delegate either (since it never started, it can’t
> fail). It will also fail if you add one or both of the keys but forget
> to explicitly request authorization. So the first thing you need to do
> is to add one or both of the following keys to your Info.plist file:


- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysUsageDescription

Both of these keys take a string
> which is a description of why you need location services. You can
> enter a string like “Location is required to find out where you are”
> which, as in iOS 7, can be localized in the InfoPlist.strings file.

![enter image description here][1]

[1]:

Reply

#15
The problem for me was that the class that was the `CLLocationManagerDelegate` was private, which prevented all the delegate methods from being called. Guess it's not a very common situation but thought I'd mention it in case t helps anyone.
Reply

#16
I add those key in `InfoPlist.strings` in **iOS 8.4, iPad mini 2.** It works too. I don't set any key, like `NSLocationWhenInUseUsageDescription`, in my `Info.plist`.

---
*InfoPlist.strings*:

"NSLocationWhenInUseUsageDescription" = "I need GPS information....";

---

[Base on this thread][1], it said, `as in iOS 7`, can be localized in the InfoPlist.strings. In my test, those keys can be configured directly in the file `InfoPlist.strings`.

> So the first thing you need to do is to add one or both of the > following keys to your Info.plist file:
>
> - NSLocationWhenInUseUsageDescription
> - NSLocationAlwaysUsageDescription
>
> Both of these keys take a string which is a description of why you
> need location services. You can enter a string like “Location is
> required to find out where you are” which, as in **iOS 7**, can be
> localized in the InfoPlist.strings file.

---
**UPDATE:**

I think [`@IOS`'s method is better.][2] Add key to `Info.plist` with empty value and add localized strings to `InfoPlist.strings`.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#17
Keep **Cocoa Keys** information always at your fingertips for those updates, here is the link:

[To see links please register here]


Enjoy.
Reply

#18
This is issue with ios 8
Add this to your code

if (IS_OS_8_OR_LATER)
{
[locationmanager requestWhenInUseAuthorization];

[locationmanager requestAlwaysAuthorization];
}
and to info.plist:

<key>NSLocationUsageDescription</key>
<string>I need location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>I need location</string>
Reply

#19
- (void)startLocationManager
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];
[locationManager requestWhenInUseAuthorization]; // Add This Line


}


And to your info.plist File
![enter image description here][1]


[1]:
Reply

#20
I get a similar error in iOS9 (working with Xcode 7 and Swift 2):
**Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.**
I was following a tutorial but the tutor was using iOS8 and Swift 1.2. There are some changes in Xcode 7 and Swift 2, I found this code and it works fine for me (if somebody needs help):

import UIKit
import MapKit
import CoreLocation

class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

// MARK: Properties
@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()

self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true

}

// MARK: - Location Delegate Methods

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Errors: " + error.localizedDescription)
}
}

Finally, I put that in info.plist:
Information Property List: **NSLocationWhenInUseUsageDescription**
Value: **App needs location servers for staff**
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through