【问题标题】:AFNetworking api call after geofence or beacon event地理围栏或信标事件后的 AFNetworking api 调用
【发布时间】:2016-04-21 06:45:48
【问题描述】:

在收到“didEnterRegion”调用后,我正在尝试进行 API 调用。当应用程序在前面时,它工作得很好。但是,如果应用程序被停用或什至在后台,则永远不会拨打电话。我试图调试它,但是一旦“reportLocationEventToServerWithType”被称为调试器“死”并且永远不会进行调用。我认为这并不重要,但我正在使用 Estimote sdk 进行信标监控。 这是sn-ps的代码:

   - (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 iphone background afnetworking-2 geofencing


    【解决方案1】:

    ios 中的后台执行略有不同。如果没有项目目标下功能的一些设置,您将无法在后台执行。您应该针对特定要求(例如位置、音频等)启用后台执行,然后您应该相应地实现代码。

    您在后台执行的选项有限,例如音频播放、位置更新、有限长度任务、IP 语音等。

    请参阅apple documentation 了解有关后台执行的更多详细信息,您可以 google 后台执行,您会得到一些不错的结果。

    所以,没有在后台执行任务的原因是您没有正确配置它。

    希望这会有所帮助:)

    【讨论】:

    • 谢谢!我也试过了,但没有。在 plist 中提到了位置背景模式,并尝试使用后台任务来完成。还是没有成功...
    • 你不能从后台调用api。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 2013-05-22
    相关资源
    最近更新 更多