我想在獲得「didEnterRegion」調用後進行API調用。當應用程序在前面時,它的效果很好。但是,如果應用程序已停用,或者即使在後臺,該呼叫也不會發生。我試圖調試它,但一旦「reportLocationEventToServerWithType」被稱爲調試器「死亡」,並且調用永遠不會發生。我不認爲它很重要,但我使用Estimote sdk來進行信標監測。 以下是代碼片段:AFNetworking地理圍欄或信標事件後的API調用
- (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」在其他情況下,千萬所以其執行無關工作的罰款。
謝謝!
謝謝!我也嘗試過,但沒有。在plist中提到了位置背景模式,並試圖用後臺任務來完成。仍然沒有成功... – user2162718
你不能從背景調用API。 – Lion