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

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

记一次审核被拒的过程

被拒内容如下:

2021年8月27日 上午8:36
发件人 Apple

  1. 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 
#import 

NS_ASSUME_NONNULL_BEGIN

@interface CLLocationManager (Extent)

@end

NS_ASSUME_NONNULL_END

.m文件

#import "CLLocationManager+Extent.h"
#import 

@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"

你可能感兴趣的:(# Guideline 2.5.4 - Performance - Software Requirements关于UIBackgroundModes被拒问题)