iBeacon: Unable to detect broadcaster - Intermittent - ios

I came across this tutorial (http://www.appcoda.com/ios7-programming-ibeacons-tutorial/) about iBeacon which I found interesting. I've downloaded their source code and able to run well.
Anyway, I noticed one strange thing. There are times, when I run the broadcaster first instead of the receiver, the receiver seems to not be able to detect any beacon but if I run the receiver first, only then the beacon can be detected.
I've tried looking into other tuts but iBeacon seems like a new technology and not much reference can be found yet. Can any of you guys who had get their hands dirty into this iBeacon thing shed some light on this intermittent issue?
Your help are much appreciated.

The issue you're seeing is because the receiver app only starts 'ranging' for beacons if it detects that you have entered a region. If you start the broadcaster first, you're already inside the beacon's region, so your app might not start ranging. This sentence in the article is the clue:
Launch the receiver app and carry it far away from the broadcasting beacon and then walk towards it to simulate entering the region.
Monitoring for a beacon means that your app will only be notified when you enter or exit a region you've defined. The radius of this region could be up to ~50m, so if you're just sat next to the receiver, you shouldn't trigger one of these events unless you turn the receiver off and on again. Monitoring can be done whilst the app is running in the background or the foreground.
Ranging for beacons in a region means that the app will be notified once per second with a list of all beacons that the device can see in the specified region (ordered by distance). Ranging will call the locationManager:didRangeBeacons:inRegion: method of your CLLocationManager's delegate. The list of beacons will be constantly updated as you move around inside / outside the region and your distance to the beacons changes. Ranging is intended to happen whilst your app is in the foreground.
If you would like the app to continuously listen for beacons, try calling
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
in your viewDidLoad:, instead of in your didEnterRegion: method.

Its due to current location delegate available methods. Add this method also -
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
This will fix the issue.

Related

Is locationManager.startUpdatingLocation() really needed to monitor or range beacons?

I did not get a convincing answer to why startUpdatingLocation should be used to range beacons. Is is required to monitor/range beacons in background or to get notifications when user is already in region and starts monitoring beacons? Came across posts which say this can actually increase the battery consumption. Would like to not call this method it it is not necessary.
It is not necessary. I have built dozens of beacon apps and they all range and monitor beacons just fine without this enabled.
You only need to call that method if you also need GPS (or other geo sensor) location updates.
Try it and see!

Sometimes App is not giving notification of iBeacon when app is kill by user in ios

I am using iBeacon Technology in my application.When I open the app,beacon monitoring gets started and after that I kill the application and put the phone in sleep mode or lock the screen. If I go near to the beacon then sometimes app starts monitoring and sometimes not. Don't know what's the issue? I have set three flag for monitoring beacon region as below.
beaconRegion.notifyOnEntry = true;
beaconRegion.notifyOnExit = true;
beaconRegion.notifyEntryStateOnDisplay= true;
And When I press the lock button of the iphone. It starts monitoring for beacons and if I am in beacon region then it works perfectly..
Can anyone help me out ?
I have been working with iBeacon for around a year now, i have had the same scenarios encountered.
As per my experience with this if you are already inside a region, it takes some time to notify the 'didEnterRegion' delegate method. But if you are outside region a then entering the same you are likely to get the delegate called instantly and this depends on the Beacon Manufacture you are testing with. [More accuracy were found with RadBeacon, Estimote and Kontakt ]
Normally the TxPower configured to the beacons will be +4 dBm thats a Beacon can transmit till 70m/230". Try with going out of the region with the App in killed state and then enter the region.
When we set notifyOnEntry, notifyOnExit to YES/true, the control is with the OS LocationManager wether to notify the App about the region entry state, and you can handle it with a Notification thrown to the User and start Monitoring and then Ranging for the encountered region.

GPS monitoring in background mode for iOS

I want to implement a feature on iOS to notify user when reach a special location (such as a bus station, don't miss it), it is easy if user always put app in foreground mode, using GPS location to detect whether arrived nearly or not. The key point is how to achieve it in background mode.
One possible solution is to update GPS in background mode, something like map navigation APP, but as you know GPS is power killer, user may not like it.
See CoreLocation API, found the following delegate callbacks, I am not sure whether they work well in background mode. Any idea on this topic please share and discuss together and thanks in advance.
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0);
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_TBD,__IPHONE_5_0);
From the Location and Maps Programming Guide
In iOS, regions associated with your app are tracked at all times,
including when the app isn’t running. If a region boundary is crossed
while an app isn’t running, that app is relaunched into the background
to handle the event. Similarly, if the app is suspended when the event
occurs, it’s woken up and given a short amount of time (around 10
seconds) to handle the event. When necessary, an app can request more
background execution time using the
beginBackgroundTaskWithExpirationHandler: method of the UIApplication
class.

CBPeripheralManager Delays stopAdvertising / Location Manager ranges stopped iBeacon

I am working with two iOS devices, one is set up as an iBeacon.
I am ranging the beacon with a second iOS device and can grab its state via:
-(void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region{}
When I stop advertising on the iBeacon, the location manager on the second device continues to range/recognize the iBeacon for 5-10 seconds.
Is this expected behaviour?
Does the peripheralManager take time to wind down?
I have a setup with dedicated BTLE hardware running as iBeacons.
Actually it takes 20-30s to stop calling locationManager:didRangeBeacons:inRegion: and after that it calls locationManager:didExitRegion:
In my understanding it makes sense and it's exactly what CL is looking for because the device needs some time to make sure it really exited the region.
On the other hand, it starts ranging for beacons almost instantly after you fire the beacon up. There's no reason to wait to start ranging.
If you inspect the proximity property of the beacon you will notice that it's CLProximityUnknown during that time. Maybe you can do something with this state to do what you need.

ios - Cllocation in background

I am working on project in which I need to fire notification when user reaches particular place, even application in background. What is the best way to do this?
What I found is following.
locationManager = [CLLocationManager new];
[locationManager startUpdatingLocation];
or
[sharedService.locationManager stopMonitoringSignificantLocationChanges];
or
[locationManager startMonitoringForRegion:region];
About startUpdatingLocation I am getting continuous notification on simulator and on ipod after 3-4 mins.
Documents says it will drain battery and appstore may not accept because this methods must be used by application like navigation types.
About stopMonitoringSignificantLocationChanges documents says it uses cellular network. I am not sure whether it wil work on ipod. On my ipod not working. Does this method needs sim card?
And how does this method works? Means should I walk some distance to get this method respond? I traveled 1-2 km but it did not work.
About startMonitoringForRegion I used
if([CLLocationManager regionMonitoringEnabled])
NSLog(#"monitering enable");
else
NSLog(#"monitering not avail");
For Ipod I got monitering not avail. Also client checked on his iphone. He also did not got notification.
Please can some one explain me this method? If any other way of finding location in background then please tell.
Edit:
I am using startUpdatingLocation. On device it calls didUpdateToLocation method every after 5 mins. Will it use lot of battery? and appstore will accept this?
If I use startUpdatingLocation will appstore accept app? Since my need is just to give notification when user reach a particular place.
According to the application requirement you describe I think that
- startMonitoringForRegion:
is the best approach, look at Apple Doc snippet below...
You can use the region-monitoring service to be notified when the user crosses a region-based boundary. Region monitoring applies both to geographical regions (represented by the CLCircularRegion class) and to beacon regions (represented by the CLBeaconRegion class). You region monitoring to detect boundary crossings of the specified region and you use those boundary crossings to perform related tasks. For example, upon approaching a dry cleaners, an app could notify the user to pick up any clothes that had been dropped off and are now ready.
You app is not tracking or routing related application so using [locationManager startUpdateLocation] will be overly done I think.

Resources