IOS7 App Development Essentials(2)iBeacon

本文详细介绍了iBeacon技术的基本概念,包括RSSI信号强度指示、精度和相对距离等核心参数,并提供了iOS应用中实现iBeacon功能的具体步骤。此外,还介绍了如何通过不同状态回调来监测iBeacon设备的状态变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ——> Linked Frameworks and Libraries
I should add these features before I begin.
CoreLocation.framework
CoreBluetooth.framework

Here is the interface in project EasyUIApp.

#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <CoreBluetooth/CoreBluetooth.h>@interface EABeaconsViewController : UIViewController <CLLocationManagerDelegate, CBPeripheralManagerDelegate, UITableViewDataSource, UITableViewDelegate]]> @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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值