2014-09-19 99 views
0

当在后台状态中接收到信标信号时,是否可以触发Web服务并根据响应进行操作?当iOS应用程序处于后台状态时触发WebService

我可以在背景范围内发送信标,但在发送本地通知之前,我应该检查网络服务是否通知。任何人都可以提出任何可能的方式来做到这一点这是它现在的外观。

-(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"); 
     } 
} 
+0

当您的应用程序在后台通知时,您有大约10秒的时间执行任务。这应该有足够的时间来查询Web服务并获得结果。 – Paulw11 2014-09-19 10:36:43

回答

0

如果您还设置了监控,则您只能在后台运行。监控回调触发后(didEnterRegiondidExitRegion),您的应用程序将在后台运行约10秒钟,然后再次暂停。在此期间,如果您的代码如图所示设置,您将获得一系列回调。

如果您的Web服务响应足够快,这将工作。如果服务器速度较慢或连接不畅,则响应可能无法在10秒内恢复,在这种情况下,通知将永远不会显示。

相关问题