Ipad Air not recognising iBeacon - objective-c

I've downloaded app for configuring beacons that I bought from Accent systems. It recognises beacon that is transmitting and I can easily configure it. I've used uuidgen tool to make some UUID for beacon and set it up in application. Let's say that this generated UUID is "XXX-XXX" (I know that it's longer and that it's HEX value). So, how it's set in my beacon is following:
UUID: XXX-XXX
Major : 1111
Minor : 0001
That same UUID I used in my code. I've set my View Controller to CLLocationManagerDelegate and in viewDidLoad method I have following code:
NSUUID *myUUID = [[NSUUID alloc] initWithUUIDString:#"XXX-XXX"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:myUUID
identifier:#"Company"];
CLLocationManager *locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager startRangingBeaconsInRegion:region];
I've also set following methods in that view controller, but they never get called:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
I'm testing this on Ipad Air and bluetooth is ON.
Why do that never get called? What am I doing wrong?

You need to ask for location permission in iOS 8, and also added a the usage description string in your plist file.
Check out this answer for more detail: https://stackoverflow.com/a/24063578/361247

Related

How do I send user to external URL via an iBeacon

I am new to the world of iBeacons and Objective-C so please bear with me
I have a very simple app built now that updates a Label when the device approaches an iBeacon. What is the Objective-C code sending the device to an external URL?
For example, as you approach the iBeacon, the device is taken to a Youtube video with an explanation of what you ware seeing.
Any tips are greatly appreciated.
Here is code that will do what you want, but it will only work if the app is in the foreground:
CLLocationManager *_locationManager;
- (void)viewDidLoad
{
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:#"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] identifier: #"any-radius-networks-ibeacon-default-uuid"];
[_locationManager startMonitoringForRegion:region];
_locationManager.delegate = self;
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.radiusnetworks.com/radbeacon/"]];
}
You'd have to add extra logic to make it open special URLs for special iBeacons.

iOS7 Core Location not updating

I have a very simple app example that initialises and updates the users location.. On device it successfully throws another callback location every second or so however on device (iPhone running iOS7) is calls the method once and then mysteriously stops...
//Setup Location Manager in ViewDidLoad
locationManager = [[CLLocationManager alloc] init];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"location services not turned on");
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(#"loactions %#", locations);
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(#"new location %f, and old %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
In iOS6 this app worked perfectly and continuously updated the devices location... What has changed since iOS7?
There are a few things here:
1- I don't see anywhere the property: pausesLocationUpdatesAutomatically. The default for this property is Yes. This means that depending on your activityType (see #2) below, the GPS will pause updates and this could be the reason you are not getting updates. The algorithm is a black box that only Apple knows and maybe it somehow changed between iOS6 and iOS7. Setting pausesLocationUpdatesAutomatically to NO can impact the battery.
2- You should set your activityType depending on your application. The default is CLActivityTypeOther which I am not sure how it impact the GPS algorithm and #1 above. So in order to test your app initially, I would set the activityType appropriately and change pausesLocationUpdatesAutomatically to No. In my test, I would get an update about every second consistently (I tested it overnight).
3- Location updates testing requires movement. In order to get better results, I would use the activityType you set, for testing. In other words, if activityType is CLActivityTypeFitness, I would walk around to test it, etc..
4- locationManager didUpdateToLocation fromLocation is deprecated in iOS7. In addition if locationManager didUpdateLocations is implemented, the former will not be called. So in your case above, locationManager didUpdateToLocation fromLocation is not being called.
5- There is no real battery usage difference between kCLLocationAccuracyBestForNavigation and kCLLocationAccuracyBest. On the other hand, kCLLocationAccuracyBestForNavigation uses top speed GPS and in addition combines it with accelerometer data.
So I would start with setting activityType, setting pausesLocationUpdatesAutomatically to NO and changing desiredAccuracy to kCLLocationAccuracyBestForNavigation. Once you are getting continuous updates, then I would set pausesLocationUpdatesAutomatically to Yes and try to work the code to achieve the same app usability.
Hope this helps

CLLocationManager updates only on Simulator Not on Devices

Here we have to update the current location by using the location manager,and its correctly updating on simulator but its not updating on device only 4 or 5 times only repeated.why the location is not updated frequently kindly hep me to solve this problem
Here i used code is showed below
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
Delegate Method:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(#"newLocation: %#",newLocation);
}
This is the delegate method is calling four or five times.
If you are using location accuracy as 'kCLLocationAccuracyBestForNavigation', your device should remain plugged in.
Better you set it as 'kCLLocationAccuracyBest'. Also move to significant distance to hit the delegate. initially it will hit 4-5 times to locate you. Once your location is identified, it will call the delegate when there will be change in your location.
So, in delegate write something in file stored in documents directory in append mode. log the lat/long and Time details into it. Now move for some distance.
Join the mobile and get the file from documents directory. It must have logg the required details.
Here i solved this problem using this delegate method
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
}

CoreLocation region delegates not called

I am building an application specifically a location based app, so I need to get the user coordinates the longitude and the latitude and its worked.
Now I need to know if the user enter some region that I predefined using the CLLocationManager delegates, so I override the didEnterRegion with an NSLog statement to know if the user enter the region.
In
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
I call the startMonitoringForRegion: but nothing happen in delegates like didEnterRegion or monitoringDidFailForRegion or any delegates for the CLRegion.
Here is some of my code :
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
locLongittude=newLocation.coordinate.longitude;
locLattiude=newLocation.coordinate.latitude;
self.regionTimer=[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:#selector(monitorRegion) userInfo:nil repeats:NO];
}
-(void)startMonitor:(float)latitude longitude:(float)longitude radius:(float)radius
{
CLLocationCoordinate2D home;
home.latitude = latitude;
home.longitude = longitude;
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:home radius:radius identifier:#"home"];
if([CLLocationManager regionMonitoringEnabled] && [CLLocationManager regionMonitoringAvailable])
[locManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
NSLog(#"Count: %d region aval %d enable %d",[[locManager monitoredRegions]count], [CLLocationManager regionMonitoringAvailable],[CLLocationManager regionMonitoringEnabled]);
for( CLRegion* region in locManager.monitoredRegions )
NSLog( #"%#", region );
}
-(void)monitorRegion
{
[self startMonitor:31.971160 longitude:35.832465 radius:10000.0];
}
Edit : all the testing done using the simulator and simulate the location using Product-> Debug -> Simulate Location
Ok guys it works. The code above works great the problem was that is to make the didEnterRegion method get called is to be outside the region you need to enter then you enter it to make it work.
What I was doing is in the simulation I always choose a coordinate inside the region I need to enter and that was the problem it must be outside the region.
So here is my code to share with you
Update : I am wondering why the didExitRegion doesn't get called when I leave the region?
As per my own experience, it looks like Region Monitoring depends on Cell Change events (why Apple designed it this way? I guess to increase the battery life). So, this implementation is not ideal.
Ideally it should work whenever you cross the boundary, but it doesn't happens the same way on iPhone. Even with the builtin Reminder app, sometimes it fails for nearby by location-based reminders.
So in your case I think the cell change event doesn't occur and that why didExitRegion is not called. You can double check it by using startMonitoringSignificantLocationChanges.

Delegation and retrieving info on IOS

I'm trying to get heading info from CLLocationManager but it's not getting called. I did everything as the documentation says, but something is very wrong.
I'm using locationManager delegating into my app delegate.
Here is the method to retrieve heading messages:
- (void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
NSLog(#"%#", newHeading);
}
Here is the part from main()
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager startUpdatingHeading];
But nothing happens! With debugging, NSLog is never getting called.
When I do same with [locationManager startUpdatingLocation] everything works fine, shows the location info, using another method (very same looking but using
- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
but I need heading info here.
Found the deal.
Code is perfectly fine, the issue is in Iphone simulator.
Somehow it is providing location info just fine, but heading info is not provided thus the message is never sent.
Talk about weird things, apple.