gpt4 book ai didi

ios - CLConnection::sendMessageInternal 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:49 25 4
gpt4 key购买 nike

我需要帮助来解决这次崩溃。

当我的应用检查 CLLocation 授权状态时,我有一个常见的崩溃(#1 崩溃,受影响的设备约 300 台):

enter image description here

'启动'方法如下:

-(BOOL)start {
if ([self isDenied]) {
return NO;
} else {
_manager = [[CLLocationManager alloc] init];
_manager.delegate = self;

if ([_manager respondsToSelector:@selector(requestAlwaysAuthorization)] && [self isNotDetermined]) {
[_manager requestAlwaysAuthorization];
} else {
[self startUpdatingLocation];
}
return YES;
}
}

'isNotDetermined' 方法,应用程序似乎从该方法切换到不同的线程并崩溃,是:

- (BOOL)isNotDetermined {
return CLLocationManager.authorizationStatus == kCLAuthorizationStatusNotDetermined;
}

也许也相关,isDenied 方法;根据文档,如果授权状态为 Denied 或 Restricted,则不应创建 CLLocationManager:

- (BOOL)isDenied {
return CLLocationManager.authorizationStatus == kCLAuthorizationStatusDenied;
}

可能是应用程序崩溃了,因为我在 authorizationStatus 为 Restricted 时创建了 CLLocationManager?在这种情况下,我预计崩溃会发生在 CLLocationManager init 方法中。

最佳答案

我/我们已经找到问题所在。问题是双重的:

  1. 应用程序进入后台时未调用 stopUpdatingLocation。
  2. 当应用程序进入前台时,CLLocationManager 被重新初始化,而没有先停止旧实例。两位代码:
// called in both didFinishLaunching and applicationWillEnterForeground
-(void) start {
_manager = [[CLLocationManager alloc] init];
// other setup code
}

// Called in applicationDidEnterBackground
-(void)stop {
// this variable was never false
if (_updateBackgroundLocations) {
[_manager stopUpdatingLocation];
}
}

我做了什么来修复它:

-(void) start {
if (_manager == nil) {
_manager = [[CLLocationManager alloc] init];
}
// other setup code
}

-(void)stop {
[_manager stopUpdatingLocation];
}

这修复了……几千次崩溃。它们可能发生在应用程序已经在后台时,因为我们从未收到用户关于频繁发生崩溃的投诉。

关于ios - CLConnection::sendMessageInternal 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32698342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com