gpt4 book ai didi

geolocation - 如何在后台正确使用位置 - 应用被拒绝 3 次

转载 作者:行者123 更新时间:2023-12-04 10:42:09 26 4
gpt4 key购买 nike

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

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.

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.

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

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



现在,据我所知,我正在后台运行并“做某事”......
在我的 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];
}

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

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.



有什么我在这里想念的吗?

最佳答案

在 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;
}

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

关于geolocation - 如何在后台正确使用位置 - 应用被拒绝 3 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com