如何在后台正确使用位置 - 应用被拒绝 3 次 [英] How to properly use location in background - app got rejected 3 times

查看:11
本文介绍了如何在后台正确使用位置 - 应用被拒绝 3 次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用被 Apple 拒绝了 3 次,所有拒绝信都是一样的,即:

My app got rejected by Apple three times, all with the same rejection letter, which is:

我们发现您的应用使用了后台模式但不包括需要该模式持续运行的功能.这个行为不符合 App Store 审核指南.

We found that your app uses a background mode but does not include functionality that requires that mode to run persistently. This behavior is not in compliance with the App Store Review Guidelines.

我们注意到您的应用声明支持位置UIBackgroundModes 键在您的 Info.plist 但不包括功能需要持久的位置.

We noticed your app declares support for location in the UIBackgroundModes key in your Info.plist but does not include features that require persistent location.

添加需要位置更新的功能是合适的当应用程序在后台或删除位置"设置时从 UIBackgroundModes 键.

It would be appropriate to add features that require location updates while the app is in the background or remove the "location" setting from the UIBackgroundModes key.

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

If you choose to add features that use the Location Background Mode, please include the following battery use disclaimer in your Application Description:

"继续使用后台运行的GPS可以显着减少电池寿命."

"Continued use of GPS running in the background can dramatically decrease battery life."

有关背景模式的信息,请参阅部分iOS 参考库中的在后台执行代码".

For information on background modes, please refer to the section "Executing Code in the Background" in the iOS Reference Library.

现在,据我所知,我正在后台运行并做某事"...在我的 AppDelegate 中,didFinishLaunchingWithOptions 中有以下代码:

Now, as far as I know I am running on the background and "doing something"... In my AppDelegate I have the following code in 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 还启动了一个位置管理器并使自己成为委托人.然后,我有以下代码来处理后台的位置更新:

The AppDelegate also starts a location manager and makes himself the delegate. Then, I have the following code for handling the location updates on the background:

 - (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];
}

我还在我的应用描述页面中添加了免责声明:

I also put a disclaimer in my app description page:

大量使用在后台运行的 GPS 会显着缩短电池寿命.出于这个原因,MY_APP_NAME 在后台运行,只是监听重大的位置变化.

Intensive use of GPS running in the background can dramatically decrease battery life. For this reason, MY_APP_NAME runs on the background just listening for significant location changes.

这里有什么我遗漏的吗?

Is there anything I'm missing here?

推荐答案

在 locationManager:didUpdateToLocation:fromLocation: 或在 updateMyLocationToServer: 您应该检查应用程序是否处于后台状态,例如.

In locationManager:didUpdateToLocation:fromLocation: or in updateMyLocationToServer: You should check if application is in background state by eg.

[UIApplication sharedApplication].applicationState == UIApplicationStateBackground

然后如果您的应用程序处于后台模式,您应该使用例如.

And then if Your app is in background mode You should use eg.

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

/*Write Your internet request code here*/

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

这种方式应用程序应该完全执行此任务.

This way application should perform this task completely.

这篇关于如何在后台正确使用位置 - 应用被拒绝 3 次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆