Search code examples
iosxcodeswiftcore-locationtestflight

CoreLocation not working for Adhoc Distribution on iOS 8


I've been developing an app that depends on CoreLocation since the first Xcode 6 beta 1. Last week I submitted it for test on iTunes connect/TestFlight. The app works perfectly on develop devices, but when I create adhoc version, it doesn't ask for authorization.

The details:

  • Settings > General > Reset > Reset Location Warnings didn't solve
  • I set NSLocationWhenInUseUsageDescription on Info.plist
  • CoreLocation.framework is added on Linked Frameworks and Libraries (but nothing changed when I remove)
  • I'm using cocoapods for MBProgressHUD
  • My ViewController is like: https://gist.github.com/thiagogabriel/d0120547565c91089b72
  • I recently changed the Product Name to lowercase
  • I started a new project from scratch and it happened the same on Adhoc for internal testers

Solution

  • Change this code:

    func askForLocation(sender: AnyObject) {
        if (locationStatus == CLAuthorizationStatus.Denied) {
            let url = NSURL.URLWithString(UIApplicationOpenSettingsURLString)
            UIApplication.sharedApplication().openURL(url)
        } else if (locationStatus != CLAuthorizationStatus.AuthorizedWhenInUse) {
            locationManager.requestWhenInUseAuthorization()
        } else if (locationStatus == CLAuthorizationStatus.AuthorizedWhenInUse){
            self.performSegueWithIdentifier("seguePlaceViewController", sender: sender)
        }
    }
    

    to

    func askForLocation(sender: AnyObject) {
        locationManager.requestWhenInUseAuthorization()
    
        if (locationStatus == CLAuthorizationStatus.Denied) {
            let url = NSURL.URLWithString(UIApplicationOpenSettingsURLString)
            UIApplication.sharedApplication().openURL(url) 
        } else if (locationStatus == CLAuthorizationStatus.AuthorizedWhenInUse){
            self.performSegueWithIdentifier("seguePlaceViewController", sender: sender)
        }
    }
    

    This update solves your problem.