Reputation: 1287
I am developing an app to search nearest beacon device but not able to calling any delegate, Already I have beacons available but not finding any beacons.
Also I did not understand NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"3863C90B-1BA6-4A4E-ADD2-D64FF1286898"];
is static is passed or not?
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"3863C90B-1BA6-4A4E-ADD2-D64FF1286898"];
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
identifier:@"com.jss.myidentifire"];
self.myBeaconRegion.notifyOnEntry = YES;
[self.locationManager startMonitoringForRegion:self.myBeaconRegion];
[self.locationManager startUpdatingHeading];
[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[locationManager requestStateForRegion:region];
}
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (state == CLRegionStateInside)
{
[self locationManager:locationManager didEnterRegion:region];
}
}
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion *)region
{
// We entered a region, now start looking for our target beacons!
self.statusLabel.text = @"Finding beacons.";
[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:@"DidEnterRegion Called" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region
{
// Exited the region
self.statusLabel.text = @"None found.";
[self.locationManager stopRangingBeaconsInRegion:self.myBeaconRegion];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:@"didExitRegion Called" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
-(void)locationManager:(CLLocationManager*)manager
didRangeBeacons:(NSArray*)beacons
inRegion:(CLBeaconRegion*)region
{
self.statusLabel.text = @"Beacon found!";
CLBeacon *foundBeacon = [beacons firstObject];
NSString *uuid = foundBeacon.proximityUUID.UUIDString;
NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];
NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];
NSString *accuracy = [NSString stringWithFormat:@"%f", foundBeacon.accuracy];
accuracy = [NSString stringWithFormat:@"%f", foundBeacon.accuracy];
if (foundBeacon.proximity == CLProximityUnknown) {
self.distanceLabel.text = @"Unknown Proximity";
} else if (foundBeacon.proximity == CLProximityImmediate) {
self.distanceLabel.text = @"Immediate";
} else if (foundBeacon.proximity == CLProximityNear) {
self.distanceLabel.text = @"Near";
} else if (foundBeacon.proximity == CLProximityFar) {
self.distanceLabel.text = @"Far";
}
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:uuid forKey:@"uuid"];
[dict setObject:major forKey:@"major"];
[dict setObject:minor forKey:@"minor"];
[dict setObject:accuracy forKey:@"accuracy"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:[NSString stringWithFormat:@"%@",dict] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
Upvotes: 0
Views: 827
Reputation: 64916
Make sure you have obtained permission to scan for beacons by adding the following:
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
For the above to work, you also need to add a new key to your Info.plist file: NSLocationAlwaysUsageDescription
with a value set to something like "This app wants to scan for beacons"
Upvotes: 2
Reputation: 138
if you start the receiver when it's already in the beacon range, it's not going to fire. Just checking that you're walking far away from the beacon and then walking back into range to get it to fire?
Upvotes: -1