如何在后台正确使用地点 - 应用得到了拒绝3次 [英] How to properly use location in background - app got rejected 3 times

查看:144
本文介绍了如何在后台正确使用地点 - 应用得到了拒绝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:

继续使用全球定位系统在后台运行,可以显着
  减少电池寿命。

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

有关背景模式的信息,请参阅节
  执行code在后台iOS的参考图书馆

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

现在,据我知道我在后台运行并做什么......
在我的AppDelegate我有didFinishLaunchingWithOptions以下code:

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中也开始位置经理,使自己的委托。
然后,我有以下的code处理的后台位置更新:

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:

集约利用全球定位系统在后台运行,可以大大减少电池寿命。因为这个原因,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天全站免登陆