【问题标题】:Trigger a WebService when the iOS app is in background state当 iOS 应用处于后台状态时触发 WebService
【发布时间】:2014-09-19 10:09:18
【问题描述】:

当在后台状态下接收到信标信号时,是否可以触发网络服务并根据其响应采取行动??

我可以在后台为信标设置范围,但在发送本地通知之前,我应该通过网络服务检查是否通知。任何人都可以提出任何可能的方法来做到这一点。这是现在的代码。

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
      CLBeacon *beacon = [[CLBeacon alloc] init];
      beacon = [beacons lastObject];

      if (beacon.proximity == CLProximityUnknown) {
            NSLog(@"Unknown");
      } 
      else if (beacon.proximity == CLProximityImmediate) {
            NSLog(@"Immediate");
            //Here I should trigger a web-service with the beacon details to check whether to send local notification or not
      } 
      else if (beacon.proximity == CLProximityNear) {
            NSLog(@"Near");
           //Here I should trigger a web-service with the beacon details to check whether to send local notification or not
      } 
      else if (beacon.proximity == CLProximityFar) {
           NSLog(@"Far");
      }
 }

【问题讨论】:

  • 当您的应用在后台收到通知时,您有大约 10 秒的时间来执行任务。这应该足以查询 Web 服务并获得结果。

标签: ios iphone web-services background ibeacon


【解决方案1】:

如果您还设置了监控,则您只能在后台进行范围。在监视回调触发(didEnterRegiondidExitRegion)后,您的应用将开始在后台运行大约 10 秒,然后再次暂停。在此期间,如果您的代码设置如图所示,您将收到测距回调。

如果您的网络服务响应速度足够快,这将起作用。如果服务器速度慢或您的连接性较差,则响应可能不会在 10 秒内回复,在这种情况下,通知将永远不会出现。

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多