Ich entwickle eine Anwendung in Xcode 7.3 für iPhone 9.3.3 in Objective-C. Ich folgte den Vorschlägen auf dieser Seite - http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/, um den Standort des iPhone zu erhalten. Ich teste was ich bisher mit einem iPhone 9.3.3 über Blitzkabel habe.Core Location funktioniert nicht in Xcode 7.3
Ich habe "NSLocationWhenInUseUsageDescription" zum Plist mit einem Wert von "Request Location" hinzugefügt.
Ich bin verwirrt, warum das nicht funktioniert. Ich habe keine Probleme mit dem Standort über NSLog.
Jede Hilfe wird sehr geschätzt.
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) CLLocationManager *locations;
//
//@property (weak, nonatomic) IBOutlet UILabel *longitudelabel;
//@property (weak, nonatomic) IBOutlet UILabel *latitudelabel;
@end
ViewController.m
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ViewController.h"
@interface ViewController()
{
NSUserDefaults *defaults;
}
@end
@implementation PollenViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// ** Don't forget to add NSLocationWhenInUseUsageDescription in MyApp-Info.plist and give it a string
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"%@", [locations lastObject]);
}
@end
versagt, was mit ur-Code ist falsch? ist die Lage null? –
Sie werden Ihren Code debuggen müssen. Überprüfen Sie den Wert von authorizationStatus vor und nach dem Aufruf von requestWhenInUseAuthorization. Implementieren Sie auch die Delegate-Methode 'locationManager: didChangeAuthorizationStatus:', um die Änderung des Autorisierungsstatus zu sehen. –
@DuncanC Ich änderte meine .m zum folgenden - [link] (http: //i.imgur.com/m3quLKk.png), und trat mit dem Debugger durch. Wenn [self.locationManager requestWhenInUseAuthorization]; heißt nichts passiert in der App. Ich habe auch [Manager requestWhenInUseAuthorization] versucht und nichts bekommen. Irgendwelche Hinweise, wie das zu beheben ist? – Aranelmalina