在得到"didEnterRegion"调用后,我正在尝试进行API调用。当应用程序在前面时,它工作得很好。但如果该应用程序被停用,甚至处于后台,则永远不会进行呼叫。我试着调试它,但一旦调用了"reportLocationEventToServerWithType",调试器就会"死亡",并且永远不会进行调用。我认为这并不重要,但我正在使用Estimote sdk进行信标监测。以下是代码片段:
- (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region{
UIApplication *app = [UIApplication sharedApplication];
NSNumber * mallID = [self.dictBeaconsPerMall objectForKey:region.identifier];
Mall * mall = [Mall getMallWithID:mallID];
[ApplicationManager sharedInstance].locationManager.beaconRecognizedMall=mall;
[[NSNotificationCenter defaultCenter]postNotificationName:nLocationMallUpdated object:nil];
UILocalNotification * not = [[UILocalNotification alloc]init];
not.alertBody = [NSString stringWithFormat:@"DID Enter beacon region at: %@",mall.strTitle];
not.alertAction = @"alertAction";
not.soundName = UILocalNotificationDefaultSoundName;
[app presentLocalNotificationNow:not];
[[ApplicationManager sharedInstance].crashAndReportsManager reportLocationEventToServerWithType:@"beacon" andSubParam:region.identifier extraInfo:@{@"paramKey":@"key"}];
}
-(void)reportLocationEventToServerWithType: (NSString*)type andSubParam:(NSString*) strID extraInfo: (NSDictionary*)extraInfo{
NSString* udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSMutableDictionary * params = [[NSMutableDictionary alloc]init];
[params setObject:type forKey:@"type"];
[params setObject:strID forKey:@"subParam"];
[params setObject:udid forKey:@"udid"];
if(extraInfo)
[params addEntriesFromDictionary:extraInfo];
UserLogRequest * req = [[UserLogRequest alloc]initWithCallerObject:self andParams:params];
req.showHud=NO;
req.showMessage=NO;
[[ApplicationManager sharedInstance].requestManager sendRequestForRequest:req];
}
请求初始化和请求管理器"sendRequestForRequest"在数百万种其他情况下工作良好,因此它们的实现无关紧要。
谢谢!
ios中的后台执行略有不同。如果没有项目目标下功能的一些设置,您就无法在后台执行。您应该为位置、音频等特定需求启用它的后台执行,然后相应地实现代码。
您在后台执行的选项有限,如音频播放、位置更新、有限长度任务、ip语音等。
有关后台执行的更多详细信息,请参阅本苹果文档,您可以在谷歌上搜索后台执行,您会得到一些不错的结果。
所以,不在后台处理您的任务的原因是您没有正确配置它
希望这将有所帮助:)