*** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Librar
来源:互联网 发布:教育软件开发公司 编辑:程序博客网 时间:2024/05/22 13:23
iOS项目集成百度地图的时候必须设置后台模式,而AppStore上线时,项目中没有用到后台定位,导致2.16被拒,苹果要求你勾选掉Background Modes 中的Location Updates
但是当你勾选掉这个后台模式后,程序crash。crash原因如下:
*** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1861.3.25.49/Framework/CoreLocation/CLLocationManager.m:609
断言失败:提示需要设置后台模式
冲突问题对比:
1.程序不勾选后台模式:
*** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1861.3.25.49/Framework/CoreLocation/CLLocationManager.m:609
2.程序勾选上后台模式,但是app中没有用到后台定位:
苹果被拒反馈:2.16 - Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc.
解决方案:
在项目中创建CLLationManager的类目,并导入到.pch文件中作为全局的,使用runtime方式来监听,代码如下:
#import "CLLocationManager+Extend.h"
#import <objc/runtime.h>
@implementation CLLocationManager (Extend)
+ (void)load {
if ([UIDevicecurrentDevice].systemVersion.floatValue >=9.0) {
method_exchangeImplementations(class_getInstanceMethod(self.class,NSSelectorFromString(@"setAllowsBackgroundLocationUpdates:")),
class_getInstanceMethod(self.class,@selector(swizzledSetAllowsBackgroundLocationUpdates:)));
}
}
- (void)swizzledSetAllowsBackgroundLocationUpdates:(BOOL)allow {
if (allow) {
NSArray* backgroundModes = [[NSBundlemainBundle].infoDictionaryobjectForKey:@"UIBackgroundModes"];
if( backgroundModes && [backgroundModescontainsObject:@"location"]) {
[selfswizzledSetAllowsBackgroundLocationUpdates:allow];
}else{
NSLog(@"APP想设置后台定位,但APP的info.plist里并没有申请后台定位");
}
}else{
[selfswizzledSetAllowsBackgroundLocationUpdates:allow];
}
}
@end
- *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Librar
- 报错:*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Librar
- Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Li
- *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/C
- Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Li
- Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Cache
- Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /BuildRoot/Library/C
- Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /BuildRoot/Library/C
- *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/co
- Assertion failure in -[GPUImageMovieWriter createDataFBO]
- *** Assertion failure in -[UITableView _endCellAnimationsWithContext:]
- Assertion failure in -[UIView layoutSublayersOfLayer:],
- Assertion failure in -[UICGColor encodeWithCoder:]
- *** Assertion failure in -[UITableView layoutSublayersOfLayer:]
- Assertion failure in -[UIView layoutSublayersOfLayer:]
- Assertion failure in -[MASViewConstraint install]
- *** Assertion failure in -[UICollectionViewData validateLayoutInRect:]
- Assertion failure in -[UICollectionView layoutSublayersOfLayer:]
- 多重继承下的虚函数调用~
- 【Android之垂直翻页公告】
- ADT、SDK、JDK、
- Jmeter mysql jdbc 测试简单示例
- 金蝶KIS迷你版标准版备份助手V2.0
- *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Librar
- Android Browser App 源码分析(一)
- Android解析XML方式(二)使用PULL解析XML
- View 的滑动冲突
- 延时函数
- Django学习,HelloWorld应用
- iOS Bluetooth 打印小票
- SQL查询排序
- linux常用的查看设备的命令