新项目,用Xcode5基于iOS 7开发,今天发现貌似掉入一个地图API的坑了。
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
根本不调用(注,已经设置了self.mapViewer.showsUserLocation = YES
)
然后会出现如下错误
2013-10-15 22:34:18.754 FloweryFairy-iOS7[3879:a0b] Cannot find executable for CFBundle 0x9dc8540 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/AccessibilityBundles/GeoServices.axbundle> (not loaded)
Oct 15 22:34:19 Hseecoms-iMac.local FloweryFairy-iOS7[3879] <Error>: CGBitmapContextCreate: unsupported parameter combination: 5 integer bits/component; 16 bits/pixel; 3-component color space; kCGImageAlphaNoneSkipLast; 512 bytes/row.
2013-10-15 22:34:19.164 FloweryFairy-iOS7[3879:9303] vImage decode failed, falling back to CG path.
没办法,把之前基于iOS 6的例子,编译测试。发现如果是iOS 6没有任何问题,如果设置为iOS 7就出现同样的问题。
网络搜索发现 下面两个帖子遇到了同样的问题!
http://www.cocoachina.com/bbs/read.php?tid=159223
http://www.cocoachina.com/bbs/m/read.php?tid=159477#read
问问这里有人遇到了这个问题么,Stackoverflow上暂时没看到别人问这个问题的。@tinyfool 帮忙转转。
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
像是那个代码里面有问题,而不是这个东西不被调用了,你把代码贴出来看看。
@interface XixiMainViewController ()
@property (strong, nonatomic) IBOutlet MKMapView *mapViewer;
@property (nonatomic, strong) CLLocationManager * locationManager;
@end
@implementation XixiMainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIColor * background = [UIColor colorWithRed:0.43137f green:0.8f blue:0.94118 alpha:1.0f];
[self.view setBackgroundColor:background];
// init the map kit view
self.mapViewer.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
self.mapViewer.delegate = self;
//
self.mapViewer.showsUserLocation = YES;
self.mapViewer.zoomEnabled = YES;
self.mapViewer.scrollEnabled = YES;
// check the whether the location services is enable
if ([CLLocationManager locationServicesEnabled]) {
// enable
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
// set the location accuracy
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.locationManager startUpdatingLocation];
} else {
// show the alert window
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"为了获得更好的体验,请开启GPS定位服务!"
delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// log current position
NSLog(@"Current Position(%f, %f)", userLocation.coordinate.latitude, userLocation.coordinate.longitude);
MKCoordinateRegion currentRegion = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 500, 500);
[self.mapViewer setRegion:currentRegion animated:YES];
}
11楼 @tinyfool @sycxl 两位老师,我应该是还原了Bug的。
我用iMAC的Sharing来Share了一个WIFI,然后iPhone 5(iOS 7)连上WIFI
在此种情况下,不能定位,也当然不调用-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
但是我关掉iPhone上的WIFI,连上3G网络,马上可以定位。
昨晚回家的路上,再次打开,发现能够定位,所以今天来做了这个实验。
BTW:@tingfool 我设置了showUserLocation属性,也看到了那个文档说明,需要check才能够定位。