title: iBeacon App only working sometimes, transmitting never working on iPhone 5
body: <p>I am having a really weird problem here. I am trying to build an app to detect beacons. I don't have any real beacons yet so I am testing with an iPhone 5 and an iPad 3. The strange thing is that the transmitting is only working on the iPad, the iPhone doesn't work as a transmitter even though I used the same app on it.</p>
  
  <p>But even with the iPad as a transmitter, the app only works sometimes - sometimes the iPhone will notify me that it has found a beacon, sometimes it doesn't. I've force-closed the app on the iPad and after the restart it worked, but then another time it doesn't. 
  Since everything is working sporadically I think it can't be the code causing that behaviour, but it might be - I am not an experienced coder, I've just started this. My code is based on this tutorial <a href="http://www.devfright.com/ibeacons-tutorial-ios-7-clbeaconregion-clbeacon/" rel="nofollow noreferrer">http://www.devfright.com/ibeacons-tutorial-ios-7-clbeaconregion-clbeacon/</a></p>
  
  <p>I first thought <a href="https://stackoverflow.com/a/21707853/2700042">this</a> might be the answer, but taht didn't solve it: it still did work sometimes, and sometimes it didn't.</p>
  
  <p>Can anybody tell me what I am dealing with her? </p>
  
  <p>Here is my code for the Tracker:</p>
  
  <p>ladBeaconTracker.h </p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;CoreLocation/CoreLocation.h&gt;
  #import &lt;CoreBluetooth/CoreBluetooth.h&gt;
  
  @interface ladBeaconTracker : UIViewController &lt;CLLocationManagerDelegate&gt;
  
  @property (strong, nonatomic) CLBeaconRegion *beaconRegion;
  @property (strong, nonatomic) CLLocationManager *locationManager;
  @property (weak, nonatomic) IBOutlet UILabel *beaconFoundLabel;
  
  @end
  </code></pre>
  
  <p>ladBeaconTracker.m</p>
  
  <pre><code>#import "ladBeaconTracker.h"
  
      @interface ladBeaconTracker ()
  
      @property NSUUID *uuid;
  
  @end  
  
  @implementation ladBeaconTracker
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
  
      self.locationManager = [[CLLocationManager alloc] init];
      self.locationManager.delegate = self;
  
      [self initRegion];
  }  
  
  - (void)initRegion {
      NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A5456D78-C85B-44C6-9F20-8268FD25EF8A"];
      self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:@"Museum"];
  
      [self.locationManager startMonitoringForRegion:self.beaconRegion];
  
      NSLog(@"Region %@ initated", _beaconRegion.identifier);
  }
  
  - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { 
      [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];       
      self.beaconRegion.notifyEntryStateOnDisplay = YES;
  
      NSLog(@"Region %@ entered", _beaconRegion.identifier);
  }
  
  - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
      [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
  
      NSLog(@"Region %@ exit", _beaconRegion.identifier);
  }
  
  - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{
      CLBeacon *beacon = [[CLBeacon alloc] init];
      beacon= [beacons lastObject];    
      self.beaconFoundLabel.text =@"Yes";
  
      NSLog(@"Ranged Region %@", _beaconRegion.identifier );
  }
  
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  /*
  #pragma mark - Navigation
  
  // In a storyboard-based application, you will often want to do a little preparation before navigation
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
      // Get the new view controller using [segue destinationViewController].
      // Pass the selected object to the new view controller.
  }
  */
  
  @end
  </code></pre>
  
  <p>And this is the transmitter-Code:</p>
  
  <p>configViewController.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;CoreLocation/CoreLocation.h&gt;
  #import &lt;CoreBluetooth/CoreBluetooth.h&gt;
  
  @interface ConfigViewController : UIViewController &lt;CBPeripheralManagerDelegate&gt;
  
  @property (strong,nonatomic) CLBeaconRegion *beaconRegion;
  @property(strong,nonatomic) NSDictionary *beaconPeripheralData;
  @property (strong, nonatomic) CBPeripheralManager *PeripheralManager;
  
  @end
  </code></pre>
  
  <p>ConfigViewController.m</p>
  
  <pre><code>#import "ConfigViewController.h"
  
  @interface ConfigViewController ()
  
  @end
  
  @implementation ConfigViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
      [self initBeacon];  
  }
  
  - (void) peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
      if (peripheral.state == CBPeripheralManagerStatePoweredOn) {
          NSLog(@"Powered ON");
          [self.PeripheralManager startAdvertising:self.beaconPeripheralData];
      }
      else if (peripheral.state == CBPeripheralManagerStatePoweredOff){
          NSLog(@"Powered OFF");
          [self.PeripheralManager stopAdvertising];
      }
  }
  
  - (void)initBeacon {
      NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A5456D78-C85B-44C6-9F20-8268FD25EF8A"];
      self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                  major:1
                                                  minor:1
                                                  identifier:@"Museum"];
  }
  
  - (IBAction)transmitBeacon:(UIButton *)sender {
      self.beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil];
      self.PeripheralManager = [[CBPeripheralManager alloc]initWithDelegate:self queue:nil options:nil];
  }
  
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  @end
  </code></pre>