我试着在StackOverflow上查看所有这些问题,但找不到任何有帮助我的东西。我自己甚至无法复制它,我是通过iTunes Connect从实际用户那里得到的。这是Xcode上的崩溃日志:
这是我的完整serializedLocations方法崩溃,没有任何内容被删除:
- (NSMutableArray *)serializedLocations:(NSArray *)locations withTimestamp:(NSInteger)timestamp{
NSMutableArray *serializedLocations = [NSMutableArray new];
if(locations){
for (CLLocation *location in locations) {
NSInteger locationTimeInterval = floor([location.timestamp timeIntervalSince1970] * 1000);
NSInteger t = locationTimeInterval - timestamp;
NSMutableDictionary *serializedLocation = [NSMutableDictionary new];
serializedLocation[@"x"] = [NSNumber numberWithDouble:location.coordinate.latitude];
serializedLocation[@"y"] = [NSNumber numberWithDouble:location.coordinate.longitude];
serializedLocation[@"a"] = [NSNumber numberWithDouble:location.horizontalAccuracy];
serializedLocation[@"v"] = [NSNumber numberWithDouble:location.speed];
serializedLocation[@"o"] = [NSNumber numberWithDouble:location.course];
serializedLocation[@"t"] = [NSNumber numberWithLong:t];
[serializedLocations addObject:serializedLocation];
}
}
return serializedLocations;
}
我似乎无法找到这个缺陷。
编辑:
获取所有其他方法的父进程如下所示:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[ApiClient insertEvent:event withLocations:locations];
});
答案 0 :(得分:2)
我猜测locations
虽然在这里输入为NSArray,但实际上是一个NSMutableArray - 这个是在枚举时被突变的数组它。如果要在后台线程上运行此代码,则需要确保locations
不会发生变异,并且#34;在后面"后面。一种简单的方法是在调用站点制作locations
的深层副本,然后传递 而不是可变数组。 (请注意,仅在serializedLocations:withTimestamp:
中进行深层复制是不够的,因为locations
在复制期间可能会突变。)