-->

如何在后台正常使用位置 - 应用程序得到了拒绝3倍(How to properly use loca

2019-07-29 08:28发布

我的应用得到了由苹果公司拒绝了三次,都具有相同的拒绝信,那就是:

我们发现您的应用使用背景模式,但不包括要求模式持续运行的功能。 这种行为是不符合在App Store审查指南。

我们注意到您的应用程序宣称支持位置在你的Info.plist的UIBackgroundModes关键,但不包括需要持续的位置信息的功能。

这将是适当补充需要位置更新,而应用程序是在后台或删除“位置”从UIBackgroundModes键设置功能。

如果您选择添加使用该位置的背景模式的功能,请在您的应用说明以下电池使用免责声明:

“在后台运行,持续使用GPS会大大减少电池寿命。”

有关背景模式的信息,请参阅iOS的参考图书馆“在后台执行代码”一节。

现在,据我所知,我在后台运行,并“做什么” ......在我的AppDelegate我在didFinishLaunchingWithOptions以下代码:

    if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsLocationKey] &&
    ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]))
{
    id locationInBackground = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
    if ([locationInBackground isKindOfClass:[CLLocation class]]) 
    {
        [self updateMyLocationToServer:locationInBackground];
    }
    else
    {
        //Keep updating location if significant changes
        CLLocationManager *locationManager = [[CLLocationManager alloc] init];
        self.bgLocationManager = locationManager;
        self.bgLocationManager.delegate = self;
        self.bgLocationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        [bgLocationManager startMonitoringSignificantLocationChanges];
    }
}

在AppDelegate中也开始位置经理,让自己的代表。 然后,我有处理的背景位置更新下面的代码:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    [self updateMyLocationToServer:newLocation];
}


-(void)updateMyLocationToServer:(CLLocation*)myNewLocation
{
    //    NSLog(@"Updating Location from the background");

    NSString *fbID = [NSString stringWithString:[facebookDetails objectForKey:@"fbID"]];
    NSString *firstName = [NSString stringWithString:[facebookDetails objectForKey:@"firstName"]];
    NSString *lastName = [NSString stringWithString:[facebookDetails objectForKey:@"lastName"]];

    NSString *urlString = [NSString stringWithFormat:@"MY_SERVER_API", fbID, myNewLocation.coordinate.latitude, myNewLocation.coordinate.longitude, firstName, lastName];


    NSURL *url = [NSURL URLWithString:urlString];

    __block ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];

    [newRequest setCompletionBlock:^{


    }];

    [newRequest setFailedBlock:^{

    }];

    //    [newRequest setDelegate:self];
    [newRequest startAsynchronous];
}

我也把一份免责声明我的应用程序的说明页面:

在后台运行的集约利用GPS可以大大减少电池寿命。 出于这个原因,MY_APP_NAME只运行在监听显著位置变化的背景。

有什么我丢失在这里吗?

Answer 1:

在的LocationManager:didUpdateToLocation:fromLocation:或updateMyLocationToServer:你应该检查是否应用程序在后台状态例如通过。

[UIApplication sharedApplication].applicationState == UIApplicationStateBackground

然后如果你的应用程序在后台模式,您应该使用如。

backgroundTask = [[UIApplication sharedApplication]
                    beginBackgroundTaskWithExpirationHandler:
                    ^{
                        [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
                    }];

/*Write Your internet request code here*/

if (bgTask != UIBackgroundTaskInvalid)
{
    [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
    bgTask = UIBackgroundTaskInvalid;
}

这样,应用程序应该完全执行此任务。



Answer 2:

这个问题是旧的,已经回答了,但你不需要的UIBackgroundModes关键,如果你使用收集的位置startMonitoringSignificantLocationChanges API



Answer 3:

startMonitoringSignificantLocationChanges不需要后台模式注册。 只有不断的改变位置做。



文章来源: How to properly use location in background - app got rejected 3 times