2014-07-18 12 views
5

मैं एक मुद्दा घेरने की कोशिश की है कि जीपीएस सेवाओं, iOS 7 पर पूरी तरह से काम है, लेकिन iOS 8 पर मैं कभी नहीं अनुमति अनुरोध और विधि मिलती है:iOS 8 GPS अक्षम है

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
कभी नहीं

कहा जाता हो जाता है।

मेरे कोड यहाँ है:

#import "Locator.h" 

@implementation Locator 

- (instancetype) init { 
    if (self = [super init]) { 
     // Start up the location manager 
     self.locationManager = [[CLLocationManager alloc] init]; 
     self.locationManager.delegate = self; 
     self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
     self.locationManager.distanceFilter = 3; 
     // New property for iOS6 
     if ([self.locationManager respondsToSelector:@selector(activityType)]) { 
      self.locationManager.activityType = CLActivityTypeFitness; 
     } 
     // New method for iOS8 
     if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { 
      [self.locationManager requestAlwaysAuthorization]; 
     } 
    } 
    return self; 
} 

- (void) startMonitoring:(LocationChangeCallback)callback { 
    if ([CLLocationManager locationServicesEnabled] && [CLLocationManager significantLocationChangeMonitoringAvailable]) { 
     // Register an observer for if/when this app goes into background & comes back to foreground 
     // NOTE: THIS CODE IS iOS4.0+ ONLY. 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchToLowEnergyMode) name:UIApplicationDidEnterBackgroundNotification object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchToAccurateMode) name:UIApplicationDidFinishLaunchingNotification object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchToAccurateMode) name:UIApplicationWillEnterForegroundNotification object:nil]; 

     UIApplicationState state = [[UIApplication sharedApplication] applicationState]; 

     self.locationUpdateCallback = callback; 

     if (state == UIApplicationStateActive) { 
      [self switchToAccurateMode]; 
     } else { 
      [self switchToLowEnergyMode]; 
     } 
    } 
} 

- (void) switchToAccurateMode { 
    NSLog(@"Accurate"); 
    [self.locationManager stopMonitoringSignificantLocationChanges]; 

    // Find the current location 
    [self.locationManager startUpdatingLocation]; 
} 

- (void) switchToLowEnergyMode { 
    NSLog(@"Low Energy"); 
    [self.locationManager stopUpdatingLocation]; 

    // Find the current location 
    [self.locationManager startMonitoringSignificantLocationChanges]; 
} 


#pragma mark - CLLocationDelegate Methods 

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 
    // locations contains an array of recent locations, but this app only cares about the most recent 
    // which is also "manager.location" 
    if (self.locationUpdateCallback != nil) { 
     self.locationUpdateCallback(manager.location); 
    } 
} 

- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
    NSLog(@"Location manager failed with error: %@", error); 
    if ([error.domain isEqualToString:kCLErrorDomain] && error.code == kCLErrorDenied) { 
     //user denied location services so stop updating manager 
     [manager stopUpdatingLocation]; 
    } 
} 
@end 

मैं भी स्थान सेटिंग के तहत की जाँच की और अपने आवेदन नाम के पीछे कुछ नहीं था। अन्य अनुप्रयोगों में ("हमेशा", "कभी नहीं" या "उपयोग करते समय") होता है।

उत्तर

11

आईओएस 8 के लिए आपको अपनी plist के लिए NSLocationAlwaysUsageDescription या NSLocationWhenInUseUsageDescription कुंजी जोड़नी होगी। अन्यथा यह अनुमति मांगता नहीं है।

CLLocationManagerDelegate

@implementation Locator <CLLocationManagerDelegate> 

- (instancetype) init { 
    //...... 
    self.locationManager.requestAlwaysAuthorization(); 
} 
+0

तुम भी requestWhenInUseAuthorization फोन और plist आप के लिए NSLocationWhenInUseUsageDescription जोड़ सकते हैं अगर आप केवल अपने ऐप के चल रहा है (पृष्ठभूमि में नहीं) LocationManager तक पहुंच की आवश्यकता जोड़ें। –

संबंधित मुद्दे