Can't detect iBeacon in iOS 8 - ios

I've followed online tutorials from AppCoda and Devfright to create an iBeacon detection app. I'm using an iBeacon from estimote, an iPad 3 with iOS 8. The app simply does not detect my iBeacon whereas its being detected by other iBeacon apps. I can't understand what I'm missing or doing wrong in my code.
Here's my .h file:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController<CLLocationManagerDelegate>
#property (nonatomic, strong) CLBeaconRegion *beaconRegion;
#property (nonatomic, strong) CLLocationManager *locManager;
#property (nonatomic, strong) IBOutlet UILabel *label1;
#property (nonatomic, strong) IBOutlet UILabel *label2;
#end
Here's my .m file:
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#interface ViewController () <CLLocationManagerDelegate>
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.locManager = [[CLLocationManager alloc] init];
self.locManager.delegate = self;
//default uuid for estimote beacons
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:#"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];
self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:#"com.rk.testregion"];
[self.locManager startMonitoringForRegion:self.beaconRegion];
[self locationManager:self.locManager didStartMonitoringForRegion:self.beaconRegion];
// Check if beacon monitoring is available for this device
if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Monitoring not available" message:nil delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil]; [alert show]; return;
}
}
-(void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region
{
// Beacon found!
self.label1.text = #"Welcome to";
self.label2.text = #"Location 1";
CLBeacon *foundBeacon = [beacons firstObject];
// retrieve the beacon data from its properties
NSString *uuid = foundBeacon.proximityUUID.UUIDString;
NSString *major = [NSString stringWithFormat:#"%#", foundBeacon.major];
NSString *minor = [NSString stringWithFormat:#"%#", foundBeacon.minor];
NSLog(#"UUID: %#", uuid);
NSLog(#"major: %#", major);
NSLog(#"minor: %#", minor);
}
- (void)viewDidDisappear:(BOOL)animated
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];
[super viewDidDisappear:animated];
}
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
{
[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];
self.label1.text = #"Searching again...";
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}
#end
The delegate method didRangeBeacons simply does not get called. Could someone please let me know how to fix this.

Check out the answer below, which describes some extra hoops you now need to jump through to get this working:
Location Services not working in iOS 8
Full disclosure: I have not tried this myself.

Related

Hard to get the geofencing running on test phone - IOS

This is my first post every here. Woohoo.
Here is my story ... I spent about a week trying tutorials about geofencing in IOS. The problem is that i have to do it in Objective-C for now.
I am trying to get a small app to run this geofencing but i keep having problems with the actual trigger events.
I am testing it on my actual phone (iPhone 7Plus) and i can't get to make some events show on the screen whether i'm inside the region or out.
i will paste code from the .h and .m files. these are the only ones that i have implemented so far.
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
#property (weak, nonatomic) IBOutlet UILabel *myLat;
#property (weak, nonatomic) IBOutlet UILabel *myLon;
#property (weak, nonatomic) IBOutlet UILabel *destLat;
#property (weak, nonatomic) IBOutlet UILabel *destLon;
#property (weak, nonatomic) IBOutlet UILabel *diff;
#property (weak, nonatomic) IBOutlet UILabel *answer;
#property BOOL alwaysOn;
#property BOOL isCLickOn;
#property (retain, nonatomic) CLLocationManager *locationManager;
#end
... and this what i have in my .m file:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void) viewDidAppear:(BOOL)animated{
// [self showAlertMessage:#"Test" message:#"Maybe works"];
// [self showAlertMessage:#"Test" message:#"Maybe works"];
[self setupTheAuthorizations];
if(!_isCLickOn){
[self startTheRegionMonitoring];
}
// _answer.text = #"Merge";
}
- (void) setupTheAuthorizations {
_locationManager = [[CLLocationManager alloc] init];
[_locationManager requestAlwaysAuthorization];
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
//check the type of authorization
CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus];
switch (authStatus) {
case kCLAuthorizationStatusAuthorizedAlways:
// should do somethinglike getting the things started and stuff like that ...
_alwaysOn = YES;
break;
case kCLAuthorizationStatusNotDetermined:
[_locationManager requestAlwaysAuthorization];
default:
break;
}
}
- (void) startTheRegionMonitoring {
if (_alwaysOn && [CLLocationManager isMonitoringAvailableForClass:[CLRegion class]]){
CLLocationDegrees latitude = 37.972004;
CLLocationDegrees longitude = -121.293740;
CLLocationDistance radius = 200;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:radius identifier:#"CH"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
_destLat.text = [NSString stringWithFormat:#"%f", latitude];
_destLon.text = [NSString stringWithFormat:#"%f", longitude];
_myLat.text = [NSString stringWithFormat:#"%f", _locationManager.location.coordinate.latitude];
_myLon.text = [NSString stringWithFormat:#"%f", _locationManager.location.coordinate.longitude];
[_locationManager startMonitoringForRegion:region];
}
_isCLickOn = YES;
}
- (void)locationManager:(CLLocationManager *)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
}
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region{
NSLog(#"entered region");
if ([region.identifier isEqualToString:#"CH"]){
_answer.text = #"IN";
CLLocation *me = [[CLLocation alloc] initWithLatitude:_locationManager.location.coordinate.latitude
longitude:_locationManager.location.coordinate.longitude];
CLLocation *dest = [[CLLocation alloc] initWithLatitude:37.972004
longitude:-121.293740];
int dist = [me distanceFromLocation:dest];
_diff.text = [NSString stringWithFormat:#"%i", dist];
}
}
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region{
NSLog(#"entered region");
if ([region.identifier isEqualToString:#"CH"]) {
_answer.text = #"OUT";
CLLocation *me = [[CLLocation alloc] initWithLatitude:_locationManager.location.coordinate.latitude
longitude:_locationManager.location.coordinate.longitude];
CLLocation *dest = [[CLLocation alloc] initWithLatitude:37.972004
longitude:-121.293740];
int dist = [me distanceFromLocation:dest];
_diff.text = [NSString stringWithFormat:#"%i", dist];
}
}
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_5_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED{
NSLog(#"Monitoring started");
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(#"error");
}
- (void) showAlertMessage:(NSString *)title message:(NSString *)message {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
What happens is that i don't get any events showing on my phone even when the app is open. so I have a view controller on the storyboard that is supposed to show my location and destination location and to show the distance between the two objects. But it doesn't show it even if i walk 400 meters and then i walk back to the center.
I know that Swift is what I should use, and I will switch to Swift but for right now I am really wanting to understand the process that goes in this geofencing thing.
Any help will be appreciated. I am also pretty new at programming so I still have things that I am trying to learn and understand about Objective-C in particular.
Thank you.

Core Location not working in Xcode 7.3

I am developing an application in Xcode 7.3 for iphone 9.3.3 in Objective-C. I followed the suggestions found on this site -- http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/ to get the iphone's location. I am testing what I have so far using an iphone 9.3.3 over lightning cable.
I have "NSLocationWhenInUseUsageDescription" added to the plist with a value of "Request Location".
I am confused as to why this isn't working. I am not getting any strings with the location over NSLog.
Any help is highly appreciated.
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController<CLLocationManagerDelegate>
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (weak, nonatomic) CLLocationManager *locations;
//
//#property (weak, nonatomic) IBOutlet UILabel *longitudelabel;
//#property (weak, nonatomic) IBOutlet UILabel *latitudelabel;
#end
ViewController.m
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ViewController.h"
#interface ViewController ()
{
NSUserDefaults *defaults;
}
#end
#implementation PollenViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// ** Don't forget to add NSLocationWhenInUseUsageDescription in MyApp-Info.plist and give it a string
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(#"%#", [locations lastObject]);
}
#end
With iOS 8, requesting permission and beginning to use location services are now separate actions. Since
requestWhenInUseAuthorization
and
requestAlwaysAuthorization
methods runs asynchronously, the app can't start the location services immediately. Instead, you need to implement
locationManager:didChangeAuthorizationStatus
delegate method as follows, which fires any time the authorization status changes based on user input.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusAuthorizedAlways
|| status == kCLAuthorizationStatusAuthorizedWhenInUse) {
[manager startUpdatingLocation];
}
}
If the user has previously given permission to use location services, the delegate method will also be called after the location manager is initialized and has its delegate set with the appropriate authorization status as follows
CLLocationManager *manager = [CLLocationManager new]
Manager.delegate = self;
if [CLLocationManager locationServicesEnabled] {
[manager startUpdatingLocation];
}
I have been able to get the location and display it in the app with the following code for ViewController.m. #DuncanC's comment helped alot. This also includes the reverse geocoding.
-Used NSLocationWhenInUseUsageDescription in the Info.plists with String "Need Location".
-Made sure Settings->Privacy->Location Services->AppName was set to "While Using" not "Never".
Hope this is helpful to anyone who's stuck.
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "CoreLocation/CoreLocation.h"
#interface ViewController ()
{
NSUserDefaults *defaults;
NSString *locationfound;
}
#property (strong, nonatomic) CLLocationManager *locationManager;
#end
#implementation PollenViewController {
CLGeocoder *geocoder;
CLPlacemark *placemark;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//implement location finder
self.locationManager=[[CLLocationManager alloc] init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
//initialize geocoder for later
geocoder = [[CLGeocoder alloc] init];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
//CURRENTLY WORKING LOCATION MANAGER
//roughly based on ---/*https://gist.github.com/paulw11/84b18044942e2ceea52a8*/
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:
(CLAuthorizationStatus)status {
defaults = [NSUserDefaults standardUserDefaults];
NSLog(#"Callback");
NSLog(#"status %i",status);
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(#"Authorized");
[self.locationManager startUpdatingLocation];
} else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted) {
NSLog(#"Denied");
locationfound=[NSString stringWithFormat:#"No Location Found"];;
self.LocationLabel.text=locationfound;
}else{
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
}
}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations lastObject];
NSLog(#"Location new %#",newLocation) ;
// Reverse Geocoding
NSLog(#"Resolving the Address");
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
defaults = [NSUserDefaults standardUserDefaults];
// NSLog(#"Found placemarks: %#, error: %#", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
locationfound= [NSString stringWithFormat:#"%#, %#",
placemark.locality,
placemark.administrativeArea];
NSLog(#"%#",locationfound);
self.LocationLabel.text=locationfound;
} else {
NSLog(#"%#", error.debugDescription);
locationfound=[NSString stringWithFormat:#"No Location Found"];;
self.LocationLabel.text=locationfound;
}
} ];
}
#end
You could try
- (void)locationManager:(CLLocationManager*) manager didFailWithError:(NSError*)error
To see if the update is failing and why

How do I get the user location for the Google Places API Place Picker to work?

At the most recent Google IO, they released the Google Places API for iOS. I'm having trouble, though, when the location used to pick places isn't hard coded. I want to find places nearby with the Place Picker.
Here's a screenshot of how the current location isn't picked up:
Here's my code:
FirstViewController.h:
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
#interface FirstViewController : UIViewController
//<GMSMapViewDelegate>
#property (nonatomic,retain) CLLocationManager *locationManager;
#property (strong, nonatomic) NSString *name2;
#property (strong, nonatomic) NSString *address2;
#property (strong, nonatomic) NSString *cat;
//#property (strong, nonatomic) NSString *lat;
//#property (strong, nonatomic) NSString *lon;
//
#property double latitude;
#property double longitude;
#property (weak, nonatomic) IBOutlet UILabel *nameLabel;
#property (weak, nonatomic) IBOutlet UILabel *addressLabel;
#property (weak, nonatomic) IBOutlet UILabel *catLabel;
#end
FirstViewController.m:
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController {
GMSPlacePicker *_placePicker;
GMSMapView *mapView_;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
// locationManager.delegate = self; // we set the delegate of locationManager to self.
// locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
// [locationManager requestAlwaysAuthorization];
//
// [locationManager startUpdatingLocation]; //requesting location updates
mapView_.settings.myLocationButton = YES;
mapView_.myLocationEnabled = YES;
mapView_.hidden = YES;
NSLog(#"User's location: %#", mapView_.myLocation);
}
//
//-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
// UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"There was an error retrieving your location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
// [errorAlert show];
// NSLog(#"Error: %#",error.description);
//}
//-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
//{
// CLLocation *crnLoc = [locations lastObject];
// _lat = [NSString stringWithFormat:#"%.8f",crnLoc.coordinate.latitude];
// _lon = [NSString stringWithFormat:#"%.8f",crnLoc.coordinate.longitude];
// double _latitude = [_lat doubleValue];
// double _longitude = [_lon doubleValue];
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//- (NSString *)deviceLocation
//{
// NSString *theLocation = [NSString stringWithFormat:#"%f, %f", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];
// return theLocation;
//}
// Add a UIButton in Interface Builder to call this function
- (IBAction)pickPlace:(UIButton *)sender {
CLLocation *myLocation = mapView_.myLocation;
// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(37.788204, -122.411937);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001,
center.longitude + 0.001);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001,
center.longitude - 0.001);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
if (error != nil) {
NSLog(#"Pick Place error %#", [error localizedDescription]);
return;
}
if (place != nil) {
_name2 = place.name;
NSLog(place.name);
self.nameLabel.text = place.name;
_address2 = place.formattedAddress;
self.addressLabel.text = [[place.formattedAddress componentsSeparatedByString:#", "]
componentsJoinedByString:#"\n"];;
NSLog(place.formattedAddress);
_cat = place.types[0];
self.catLabel.text = place.types[0];
NSLog(_cat);
} else {
_name2 = #"No place selected";
_address2 = #"";
}
}];
}
- (void)requestAlwaysAuthorization
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
// If the status is denied or only granted for when in use, display an alert
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
NSString *title;
title = (status == kCLAuthorizationStatusDenied) ? #"Location services are off" : #"Background location is not enabled";
NSString *message = #"To use background location you must turn on 'Always' in the Location Services Settings";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Settings", nil];
[alertView show];
}
// The user has not enabled any location services. Request background authorization.
else if (status == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestAlwaysAuthorization];
}
}
#end
Also, is there any way I can use the place picker for the apple watch? Thanks!
By adding Core Location to the app I was able to get the coordinates for current location to be used in the place picker. Here's my code:
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(_locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:nil];

iOS Can not find the iBeacon again in fore ground

Hi~ I'm learning to use CLLocationManager to detect iBeacon. I read this article:
http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html
It says that startRangingBeaconsInRegion will make system scan beacon every second. I test and it's right.
But a problem happens if the program only execute startMonitoringForRegion without startRangingBeaconsInRegion.
My program can find the beacon first time I start a beacon hardware, and after I stop beacon the founction didExitRegion is called. But after I start the beacon second time, program cannot find it(execute didEnterRegion) at all. I have wait for 1 hour.
The Hardware I use for test are iPhone 5s with iOS 8.1.2 and radBeacon USB.
Here is my code.
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#interface ViewController () <CLLocationManagerDelegate>
#property (retain, nonatomic) IBOutlet UITextView *textView;
#property (strong, nonatomic) NSMutableString *myLog;
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (strong, nonatomic) CLBeaconRegion *beaconRegion;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self startBeaconMonitoring];
}
- (void)startBeaconMonitoring {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
_locationManager.delegate = self;
[_locationManager performSelector:#selector(requestAlwaysAuthorization)];
[self userGeofencingPreferencesWereUpdatedWithNotification:nil];
[self updateLogWithString:#"start the app"];
}
- (void) userGeofencingPreferencesWereUpdatedWithNotification: (NSNotification *) notification
{
if (1) {
NSUUID *proximityUUID = [[NSUUID UUID] initWithUUIDString:#"EEF45689-BBE5-4FB6-9E80-41B78F6578E2"];
_beaconRegion = [[CLBeaconRegion alloc]
initWithProximityUUID:proximityUUID
identifier:#"1"];
_beaconRegion.notifyEntryStateOnDisplay = YES;
[_locationManager startMonitoringForRegion:_beaconRegion];
//[_locationManager startRangingBeaconsInRegion:beaconRegion];
//[_locationManager stopUpdatingLocation];
}
}
- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[self updateLogWithString:#"enter"];
NSLog(#"enter");
}
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
[self updateLogWithString:#"exit"];
NSLog(#"exit");
}
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region {
//NSLog(#"range");
}
- (void)dealloc {
[_textView release];
[_myLog release];
[_locationManager release];
[_beaconRegion release];
[super dealloc];
}
- (NSMutableString *)myLog {
if (!_myLog) {
_myLog = [[NSMutableString alloc] init];
}
return _myLog;
}
- (void) updateLogWithString:(NSString*)newLog {
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = #"hh:mm:ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString * logWithTime = [NSString stringWithFormat:#"%#---%#\n",[dateFormatter stringFromDate:now], newLog];
[self.myLog appendString:logWithTime];
self.textView.text = self.myLog;
[dateFormatter release];
}
#end
I found something by accident and this solve my problem. When I use a iOS APP named Broadcaster to simulate a iBeacon, it triggers iBeacon detection APP very quickly which run on another iOS device no matter in foreground, background or screen off.
When I use Rad Beacon USB, still failure. I test all my 4 Rad Beacon USBs and same thing happens.
It seems that the BLE message sent by Rad Beacon USB is a little different from which simulated by iOS(I just tried the APP Broadcaster). And iOS8 treats them
different in some situations.
My Rad Beacon USBs are version 2.0.

Trouble with getting location on iphone 6.1 simulator

I am very new to objective C and Xcode. I was trying to find out the location of my iphone simulator and went through a tutorial on youtube. Following is the code.
#import "MainClassViewController.h"
#import <CoreLocation/CoreLocation.h>
#interface MainClassViewController () <CLLocationManagerDelegate>
#end
#implementation MainClassViewController
{
CLLocationManager *manager;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
manager = [[CLLocationManager alloc]init];
}
- (IBAction)LocationButton:(id)sender
{
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
#pragma mark CLLocationManagerDelegate Methods
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(CLLocation *)newLocation fromLocation: (CLLocation *) oldLocation {
NSLog(#"Location: %#", newLocation);
CLLocation *currentLocation = newLocation;
if(currentLocation != nil){
_Lattitude.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
_Longitude.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
}
}
#end
#import <UIKit/UIKit.h>
#interface MainClassViewController : UIViewController
- (IBAction)LocationButton:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *Lattitude;
#property (weak, nonatomic) IBOutlet UILabel *Longitude;
#end
My questions are:
1. I am not sure why labels are not getting updated with location.
2. I want to learn more about debugging. Any suitable resources available. Please keep in mind I do not want learn all about debugging. Only what is required for the basics.

Resources