*** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Librar
2016-06-14 11:22
621 查看
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 ([UIDevice
currentDevice].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 = [[NSBundle
mainBundle].infoDictionary
objectForKey:@"UIBackgroundModes"];
if( backgroundModes && [backgroundModes
containsObject:@"location"]) {
[self
swizzledSetAllowsBackgroundLocationUpdates:allow];
}else{
NSLog(@"APP想设置后台定位,但APP的info.plist里并没有申请后台定位");
}
}else{
[self
swizzledSetAllowsBackgroundLocationUpdates:allow];
}
}
@end
但是当你勾选掉这个后台模式后,程序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 ([UIDevice
currentDevice].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 = [[NSBundle
mainBundle].infoDictionary
objectForKey:@"UIBackgroundModes"];
if( backgroundModes && [backgroundModes
containsObject:@"location"]) {
[self
swizzledSetAllowsBackgroundLocationUpdates:allow];
}else{
NSLog(@"APP想设置后台定位,但APP的info.plist里并没有申请后台定位");
}
}else{
[self
swizzledSetAllowsBackgroundLocationUpdates:allow];
}
}
@end
相关文章推荐
- iOS7中的多任务 - Background Fetch,Silent Remote Notifications,Background Transfer Service
- iOS 后台运行实现总结
- [Android]判断是否是华为EMUI系统
- UITableView隐藏多余的分割线
- QtQuick学习笔记之QML键盘Keys事件
- easyui datagrid 多表头设置
- -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
- 【leetcode】318. Maximum Product of Word Lengths My Submissions QuestionEditorial Solution
- LeetCode-225.Implement Stack using Queues
- SDWebImage 如何为 UIImageView 添加图片
- Update statements cannot be executed as a query
- iOS UIAlterController
- 贝赛尔曲线实现圆形进度条
- QtQuick学习笔记之QML鼠标事件
- [APUE]进程环境
- UILable 字体颜色修改
- UITextField添加Block
- 用GUI完成了斗地主发牌
- View.requestLayout()
- Android中View绘制流程以及invalidate()、requestLayout()等相关方法分析