谷歌地图iOS SDK崩溃 - GMSBackgroundAppException

时间:2015-03-02 14:05:53

标签: ios iphone google-maps

我已将Google Maps for iOS SDK集成到我的应用中,我遇到了一个奇怪的崩溃。

FatalException: GMSBackgroundAppException
Background execution would crash in this scenario

0  CoreFoundation                 0x0000000183abe59c __exceptionPreprocess + 132
1  libobjc.A.dylib                    0x00000001942080e4 objc_exception_throw + 60
2  CoreFoundation                 0x0000000183abe4dc -[NSException initWithCoder:]
3  myApp                               0x00000001004c4a04 -[GMSAsyncInitServices sharedInitWithSync:]
4  myApp                               0x00000001004c48d4 -[GMSAsyncInitServices initSync]
5  myApp                               0x00000001004c5588 +[GMSServices sharedServicesSync]
6  myApp                               0x00000001004ba4a8 -[GMSMapView sharedInitWithServices:camera:]
7  myApp                               0x00000001004b9e44 -[GMSMapView initWithFrame:camera:]
8  myApp                               0x00000001004b9cdc +[GMSMapView mapWithFrame:camera:]
9  myApp                               0x0000000100103c88 -[GoogleMapViewController viewDidLoad] (GoogleMapViewController.m:63)
10 UIKit                                  0x000000018826d184 -[UIViewController loadViewIfRequired] + 692
11 UIKit                                  0x000000018826ce94 -[UIViewController view] + 32
12 myApp                               0x0000000100136cc0 -[BaseViewController viewDidLoad] (BaseViewController.m:93)
13 UIKit                                  0x000000018826d184 -[UIViewController loadViewIfRequired] + 692
14 UIKit                                  0x000000018826ce94 -[UIViewController view] + 32
15 UIKit                                  0x000000018895e90c -[_UIFullscreenPresentationController _setPresentedViewController:] + 76
16 UIKit                                  0x000000018856787c -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 120
17 UIKit                                  0x000000018858291c -[UIViewController _presentViewController:withAnimationController:completion:] + 1972
18 UIKit                                  0x000000018827ace8 +[UIView(Animation) performWithoutAnimation:] + 88
19 UIKit                                  0x0000000188584dd8 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 284
20 UIKit                                  0x000000018835a3d4 -[UIViewController presentViewController:animated:completion:] + 216
21 myApp                               0x00000001000cf1e4 -[FirstViewController viewDidAppear:] (FirstViewController.m:49)
22 UIKit                                  0x000000018828418c -[UIViewController _setViewAppearState:isAnimating:] + 592
23 UIKit                                  0x00000001882ef5fc -[UIViewController _executeAfterAppearanceBlock] + 64
24 UIKit                                  0x00000001882ef564 _applyBlockToCFArrayCopiedToStack + 356
25 UIKit                                  0x0000000188260ea0 _afterCACommitHandler + 572
26 CoreFoundation                 0x0000000183a76a50 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
27 CoreFoundation                 0x0000000183a739dc __CFRunLoopDoObservers + 360
28 CoreFoundation                 0x0000000183a73dbc __CFRunLoopRun + 836
29 CoreFoundation                 0x00000001839a10a4 CFRunLoopRunSpecific + 396
30 GraphicsServices               0x000000018cb3b5a4 GSEventRunModal + 168
31 UIKit                                  0x00000001882d2aa4 UIApplicationMain + 1488
32 myApp                               0x0000000100266818 main (main.m:16)
33 libdyld.dylib                       0x0000000194876a08 start + 4

据报道,谷歌开发网站发生类似崩溃的错误,但我不能100%确定这是否是谷歌错误,或者是否误用了SDK:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=7716

BaseViewController是我的应用程序的主视图,并在应用程序启动时(或在注册/登录后立即加载)。在它的viewDidLoad()方法中,它初始化了我的GoogleMapViewController,它只是一个保存地图的UIViewController。 GoogleMapVC的viewDidLoad()位于:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

//We have to stop Google Maps from accessing location when the app goes into the background.
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(appGoingBackground:)
                                             name:UIApplicationDidEnterBackgroundNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(appBecomeActive:)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];
self.allMarkers = [NSMutableArray array];


double latitude = 40.71448;
double longitude = -74.00598;

GPSManager *manager = [GPSManager sharedInstance];
if (manager.lastKnownLocation) {
    latitude = manager.lastKnownLocation.coordinate.latitude;
    longitude = manager.lastKnownLocation.coordinate.longitude;
}

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
                                                        longitude:longitude
                                                             zoom:5];

self.mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.mapView setMinZoom:1 maxZoom:15];
self.mapView.myLocationEnabled = YES;
[self.view addSubview:self.mapView];
[self performSelector:@selector(setPadding) withObject:nil afterDelay:0.1];
}

导致崩溃的行是这一行:

    self.mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];

崩溃报告的标题似乎表明这与后台执行有关,但正如我之前所说,这是在应用程序启动时在viewDidLoad()中执行的代码。

我有什么遗失的吗?任何想法/建议将不胜感激。

1 个答案:

答案 0 :(得分:3)

为了防止其他人遇到这种情况,Google在他们的开发板上发布了回复。

当应用在后台时实例化Google地图时会发生此崩溃。他们建议在这种情况下捕获异常,并在应用程序返回前台时重新实例化。

以下是相关Google开发板帖子的链接:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=7716