Ranging Beacons only works when app running?

后端 未结 5 699
说谎
说谎 2021-01-29 23:05

I am having difficulties getting this to work for when the app is not running. I have locationManager:didRangeBeacons:inRegion: implemented and it is called when th

5条回答
  •  生来不讨喜
    2021-01-29 23:51

    Here is the process you need to follow to range in background:

    1. For any CLBeaconRegion always keep monitoring on, in background or foreground and keep notifyEntryStateOnDisplay = YES
    2. notifyEntryStateOnDisplay calls locationManager:didDetermineState:forRegion: in background, so implement this delegate call...

    ...like this:

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{
    
       if (state == CLRegionStateInside) {
    
    
            //Start Ranging
            [manager startRangingBeaconsInRegion:region];
        }
    
       else{
    
            //Stop Ranging
            [manager stopRangingBeaconsInRegion:region];
        }
    
    }
    

    I hope this helps.

提交回复
热议问题