IOS 8 MKMapView Application Failure

I tried to move my iOS7 application using MKMapview to support iOS8. However, I was not able to receive a new request for users to indicate their locations for proper operation. I create my MKMapView on a storyboard, and the delegate is configured and works fine on iOS7. Here's what I added to support iOS8 location sharing:

myMapView.h

#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h> @interface myMapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> @property (strong, nonatomic) IBOutlet MKMapView *mapView; @property (strong, nonatomic) CLLocationManager *locationManager; 

myMapView.m

 //Code omitted #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) //Code omitted - (void)viewDidLoad { [super viewDidLoad]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; if(IS_OS_8_OR_LATER) { //[self.locationManager requestWhenInUseAuthorization]; [self.locationManager requestAlwaysAuthorization]; [self.locationManager startUpdatingLocation]; } [self.mapView setShowsUserLocation:YES]; [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = self.locationManager.location.coordinate.latitude; region.center.longitude = self.locationManager.location.coordinate.longitude; region.span.latitudeDelta = 0.0187f; region.span.longitudeDelta = 0.0137f; [self.mapView setRegion:region animated:YES]; _initialPosition = NO; } 

In addition, I set the NSLocationAlwaysUsageDescription key and its value in my InfoPlist, which shows the correct message when a user asks to share their location.

Unfortunately, the delegate function -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations never called. Although each time the viewController loads, [self.locationManager startUpdatingLocation] , but the delegate does not seem to respond to it. Is there a problem in the way I appoint a delegate, or is there something else I am missing?

UPDATE: It also seems that my gpx file is not being called at startup. I cleared and reloaded the location file, even changed it to the default location, but the location was not found: Domain=kCLErrorDomain Code=0

UPDATE 2: Here is the SS from the settings that I actually performed with the user request but cannot find / update the location, no matter how much I update. App privacy level: Location sharing always
(source: barisaltop.com )

Thanks!

+2
source share
2 answers

I had the same problem a few days ago. Solution added to Support Files /Info.plist

string keys NSLocationAlwaysUsageDescription (for [CLLocationManager requestAlwaysAuthorization] ) or NSLocationWhenInUseUsageDescription (for [CLLocationManager requestWhenInUseAuthorization] )

You can also edit the source code of Info.Plist using Right-click> open as> Source Code and add the following lines:

 <!-- for requestAlwaysAuthorization --> <key>NSLocationAlwaysUsageDescription</key> <string>Explain for what are you using the user location</string> <!-- for requestWhenInUseAuthorization --> <key>NSLocationWhenInUseUsageDescription</key> <string>Explain for what are you using the user location</string> 

Hope this helps.

+7
source

Finally, I managed to run my gpx file on the simulator. It seems that after installing Xcode 6 for the first time, an error may occur that causes the gpx files to be simulated. Here is how I overcame the problem:

  • I removed my application from the simulator
  • In the section App-> Enabled Features Backgrounds-> Location Updates
  • Run the application and install it on the simulator
  • Allow access and I was able to find the user using GPX
  • Subsequently, I turned off location updates.

I don't know why, but it did the trick for me.

+1
source

Source: https://habr.com/ru/post/976705/


All Articles