iOS 6 Map problems with MKUserTrackingModeFollowWithHeading

时间秒杀一切 提交于 2020-01-12 08:47:26

问题


I'm trying to solve two problems with MKUserTrackingModeFollowWithHeading in iOS 6:

  • MKUserTrackingModeFollowWithHeading works briefly, but it's jittery and returns to MKUserTrackingModeFollow almost immediately, especially at high zoom levels.

  • The app occasionally crashes when repeatedly changing the MKUserTrackingMode: I get EXC_BAD_ACCESS on the main thread, without further information. This is hard to reproduce, but it has happened repeatedly.

Any thoughts on what might be causing this? It feels like a bug, but Apple's own "Maps" app doesn't exhibit this behavior.

In order to isolate the problems, I've created a Single View Application with an MKMapView and a UIToolbar (set up in a .xib), to which I'm adding a MKUserTrackingBarButtonItem. The UIViewController acts as a <MKMapViewDelegate>. Here's the complete implementation code:

#import "ViewController.h"

@implementation ViewController

@synthesize mapView, toolbar;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Add MKUserTrackingBarButtonItem to toolbar
    MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
    [toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES];
}


- (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated
{
    // Log MKUserTrackingMode change
    NSString *modeType = (mode == 0) ? @"None" : ((mode == 1) ? @"Follow" : @"FollowWithHeading");
    NSLog(@"MKUserTrackingMode changed to: %@", modeType);
}

@end

回答1:


This is a bug in MapKit. It can be observed also in Apple Maps using MapKit such as the Find My Friends app. Note that the Apple Maps app is not using MapKit (at least not the same version) thus it's not affected by this bug.

I also do see sporadic EXC_BAD_ACCESS crashes in MapKit. In fact, MapKit related crashes account for the vast majority of my app's crashes. :(




回答2:


I also noticed that MKUserTrackingModeFollowWithHeading works briefly and it changes to MKUserTrackingModeFollow almost immediately, especially at high zoom levels.

I tried

- (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated {
    if (mapView.userTrackingMode != MKUserTrackingModeFollowWithHeading) {
        [mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];
    }
}

but this creates a forever loop since right after I change to MKUserTrackingModeFollowWithHeading, something changes back to MKUserTrackingModeFollow. It's really annoying because I don't know what keeps changing the tracking mode to MKUserTrackingModeFollow.

Sorry that my answer was not useful, but I posted here to confirm the problem.



来源:https://stackoverflow.com/questions/15664092/ios-6-map-problems-with-mkusertrackingmodefollowwithheading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!