---
title: "IOS7 App Development Essentials(2)iBeacon"
author: "sillycat"
date: "2014-03-05T05:55:46Z"
tags: []
categories: ["移动开发"]
slug: "ios7-app-development-essentials-2-ibeacon"
draft: false
lastmod: "2014-03-05T05:55:46Z"
id: 2025653
url: "https://sillycat.iteye.com/blog/2025653"
---

IOS7 App Development Essentials(2)iBeacon

**1. Beacon Introduction**  
**CLBeacon**  
**RSSI**(Received Signal Strength Indication)  \[-93, -113]  
**accuracy**    The accuracy of the proximity value, measured in meters from the beacon  
**proximity**    The relative distance to the beacon.

**2. Building Steps**  
General ——&gt; Linked Frameworks and Libraries  
I should add these features before I begin.  
CoreLocation.framework  
CoreBluetooth.framework

Here is the interface in project EasyUIApp.

#import &lt;UIKit/UIKit.h&gt; #import &lt;CoreLocation/CoreLocation.h&gt; #import &lt;CoreBluetooth/CoreBluetooth.h&gt;@interface EABeaconsViewController : UIViewController &lt;CLLocationManagerDelegate, CBPeripheralManagerDelegate, UITableViewDataSource, UITableViewDelegate]]&gt; @property (nonatomic,weak) IBOutletUISwitch \*advertisingSwitch; @property (nonatomic,weak) IBOutletUISwitch \*monitorSwitch; @property (nonatomic,weak) IBOutletUISwitch \*rangingSwitch; @property (nonatomic,weak) IBOutletUITableView \*beaconTableView; @end

The import Implementation are as follow:  
\- (void)locationManager:(CLLocationManager \*)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion \*)region {

//enter region - (void)locationManager:(CLLocationManager \*)manager         didEnterRegion:(CLRegion \*)region{ } //exit region - (void)locationManager:(CLLocationManager \*)manager          didExitRegion:(CLRegion \*)region{ }

//ranging beacon - (void)locationManager:(CLLocationManager \*)manager        didRangeBeacons:(NSArray \*)beacons               inRegion:(CLBeaconRegion \*)region {

**Tips**  
**1. Update the iOS Version**  
**Check your phone model**   
http://support.apple.com/kb/ht3939  
My phone model is A1428 at the back cover, it is GSM model.

Download the beta version  
https://developer.apple.com/devcenter/ios/index.action#betadownloads

Both for Xcode and iOS  
ios\_7.1\_beta\_5\_\_iphone\_5\_model\_a1428\_\_11d5145e.dmg  
xcode\_5.1\_beta5.dmg

Press ‘Option’ and click on the ‘Restore IPhone'

**2. Downgrade the iOS 7.1 beta to iOS 7.0.x**  
First of all, prepare and download the latest 7.0.x version from developer center.  
iPhone5,1\_7.0.6\_11B651\_Restore.ipsw

Hold the “Home” button and the “Power” button for 10 seconds, then release the “Power” button. The iTunes will show you that the iPhone is under Recovery Mode.

Hold the ‘alt’ ‘option’ button on my MAC book. Click on the ‘Restore IPhone’ on the iTunes. Select my lovely ipsw file.

**3. Detect the App Foreground and Background**  
\+ (void)load {    \[\[NSNotificationCenterdefaultCenter] addObserver:self            selector:@selector(handleAppLaunched) name:UIApplicationDidFinishLaunchingNotificationobject:nil];        \[\[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(handleAppResigningActive) name:UIApplicationWillResignActiveNotificationobject:nil];        \[\[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(handleAppBecomingActive) name:UIApplicationDidBecomeActiveNotificationobject:nil];        \[\[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(handleAppEnteringBackground) name:UIApplicationDidEnterBackgroundNotificationobject:nil];        \[\[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(handleAppEnteringForeground) name:UIApplicationWillEnterForegroundNotificationobject:nil];        \[\[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(handleAppClosing) name:UIApplicationWillTerminateNotificationobject:nil]; } + (void)handleAppLaunched{    NSLog(@"I am handleAppLaunched....."); } + (void)handleAppResigningActive{    NSLog(@"I am handleAppResigningActive....."); } + (void)handleAppBecomingActive{    NSLog(@"I am handleAppBecomingActive....."); } + (void)handleAppEnteringBackground{    NSLog(@"I am handleAppEnteringBackground....."); } + (void)handleAppEnteringForeground{    NSLog(@"I am handleAppEnteringForeground....."); } + (void)handleAppClosing{    NSLog(@"I am handleAppClosing....."); }

Or I can change all the method from + class method to - instance method, and call the method in my startMethod or -(void)viewDidLoad.

**References:**  
http://code-evolution.blogspot.com/2011/02/evolved-code-2-splendid-approach-for.html