Gio*_*nni 7 geolocation app-store appstore-approval
我的应用程序被苹果公司三次拒绝,所有拒绝信都是相同的,即:
我们发现您的应用使用后台模式,但不包含要求该模式持续运行的功能.此行为不符合App Store审查指南.
我们注意到您的应用程序在Info.plist中的UIBackgroundModes键中声明了对位置的支持,但不包括需要持久位置的功能.
在应用程序处于后台时添加需要位置更新的功能或从UIBackgroundModes键中删除"location"设置是合适的.
如果您选择添加使用位置背景模式的功能,请在您的应用程序说明中包含以下电池使用免责声明:
"继续使用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];
}
}
Run Code Online (Sandbox Code Playgroud)
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];
}
Run Code Online (Sandbox Code Playgroud)
我还在我的应用说明页面中放置了免责声明:
在后台运行GPS的大量使用可能会大大缩短电池寿命.出于这个原因,MY_APP_NAME在后台运行,只是在侦听重要的位置更改.
这里有什么我想念的吗?
这个问题很老,已经得到解答,但UIBackgroundModes如果您使用startMonitoringSignificantLocationChangesAPI 收集位置,则不需要密钥
在 locationManager:didUpdateToLocation:fromLocation: 或 updateMyLocationToServer: 中,您应该检查应用程序是否处于后台状态,例如。
[UIApplication sharedApplication].applicationState == UIApplicationStateBackground
Run Code Online (Sandbox Code Playgroud)
然后,如果您的应用程序处于后台模式,您应该使用例如。
backgroundTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:
^{
[[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
}];
/*Write Your internet request code here*/
if (bgTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
bgTask = UIBackgroundTaskInvalid;
}
Run Code Online (Sandbox Code Playgroud)
这样应用程序应该完全执行此任务。