App遇到崩溃后无法理解此次崩溃的原因。这个崩溃报告我是从App Store获得的。这是崩溃报告截图
它主要影响iOS 10.2。在本课程中,我使用的是谷歌地图,Pageviewcontroller和Timer。所以,任何人都可以告诉我如何找出它?
答案 0 :(得分:0)
由于使用 addObserver forKeyPath:@"myLocation" options:NSKeyValueObservingOptionNew
从Google地图获取用户当前位置,因此发生了此次崩溃。
在dealloc Google Maps中,您需要删除此观察者。否则应用程序将崩溃并出现以下错误
NSInternalInconsistencyException:类GMSMapView的实例0x1759f350已取消分配,而键值观察者仍在其中注册。当前观察信息:(上下文:0x0,属性:0x177a4490>)
在将Google地图添加到mapView之前,您需要先添加地址:
// Listen to the myLocation property of GMSMapView.
[mapView_ addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
self.view = mapView_;
// Ask for My Location data after the map has already been added to the UI.
dispatch_async(dispatch_get_main_queue(), ^{
mapView_.myLocationEnabled = YES;
});
#pragma mark - KVO updates
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (!firstLocationUpdate_) {
// If the first location update has not yet been received, then jump to that
// location.
firstLocationUpdate_ = YES;
CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
zoom:14];
}
}
然后添加此代码以删除观察者
- (void)dealloc {
[mapView_ removeObserver:self
forKeyPath:@"myLocation"
context:NULL];
}
了解更多详情:Google Maps iOS SDK, Getting Current Location of user