2014-09-19 93 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秒內恢復,在這種情況下,通知將永遠不會顯示。

相關問題