Guideline 2.5.4 - Performance - Software Requirements关于UIBackgroundModes被拒问题

68 篇文章 1 订阅
这篇博客讲述了开发者遇到的一个iOS应用审核被拒的问题,原因是应用声明了支持后台定位但未实际使用。苹果要求要么实现需要后台定位的功能,要么移除相关设置。解决方案包括移除location updates设置、使用前台定位或通过代码hook避免在不需要时开启后台定位。
摘要由CSDN通过智能技术生成

Guideline 2.5.4 - Performance - Software Requirements关于UIBackgroundModes被拒问题

记一次审核被拒的过程

被拒内容如下:

2021年8月27日 上午8:36
发件人 Apple
2. 5 Performance: Software Requirements
Guideline 2.5.4 - Performance - Software Requirements

Your app declares support for location in the UIBackgroundModes key in your Info.plist file but does not have any features that require persistent location. Apps that declare support for location in the UIBackgroundModes key in your Info.plist file must have features that require persistent location.

Next Steps

To resolve this issue, please revise your app to include features that require the persistent use of real-time location updates while the app is in the background.

If your app does not require persistent real-time location updates, please remove the “location” setting from the UIBackgroundModes key. You may wish to use the significant-change location service or the region monitoring location service if persistent real-time location updates are not required for your app features.

Resources

For more information, please review the Starting the Significant-Change Location Service and Monitoring Geographical Regions.

大致意思:您的应用程序声明支持Info.plist文件中UIBackgroundModes键中的位置,但没有任何需要持久位置的功能。在Info.plist文件的UIBackgroundModes键中声明支持位置的应用程序必须具有需要持久位置的功能。

使用location updates

如果确定使用location updates的话,描述为什么使用,那个场景使用。来进行申诉。

不使用location updates解决方案一:没有使用百度地图

1、勾掉location updates

在这里插入图片描述
或者在info.plist文件,UIBackgroundModes键中删除“location”设置。

2、删除后台定位代码 不然会引起崩溃

 if #available(iOS 9.0, *) {
   locationManager.allowsBackgroundLocationUpdates = true
 }
if #available(iOS 8.0, *) {
   locationManager.requestWhenInUseAuthorization()
}

3、使用前台定位的方法

if #available(iOS 9.0, *) {
//                locationManager.allowsBackgroundLocationUpdates = true
    locationManager.pausesLocationUpdatesAutomatically = false;
}
if #available(iOS 8.0, *) {
    locationManager.requestWhenInUseAuthorization()
}

不使用location updates解决方案二:使用百度地图

1、同上步骤

按照不使用location updates解决方案一:没有使用百度地图所有步骤。

2、添加一个类别文件 代码如下:

.h文件

#import <CoreLocation/CoreLocation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface CLLocationManager (Extent)

@end

NS_ASSUME_NONNULL_END

.m文件

#import "CLLocationManager+Extent.h"
#import <objc/runtime.h>

@implementation CLLocationManager (Extent)
+ (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

注:如果是swift项目,请使用header.h文件进行桥接导入

#import "CLLocationManager+Extent.h"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WMSmile

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值