iOS開發iBeacon藍芽技術

2021-09-29 21:40:20 字數 3333 閱讀 5900

ibeacon使用的是ble技術,具體而言,利用的是ble中名為「通告幀」(advertising)的廣播幀。通告幀是定期傳送的幀,只要是支援ble的裝置就可以接收到。ibeacon通過在這種通告幀的有效負載部分嵌入蘋果自主格式的資料來實現。

ibeacon的資料主要由四種資訊構成,分別是uuid(通用唯一識別符號)、major、minor、measured power。

uuid是規定為iso/iec11578:1996標準的128位識別符號。

major和minor由ibeacon發布者自行設定,都是16位的識別符號。比如,連鎖店可以在major中寫入區域資訊,可在minor中寫入個別店鋪的id等。另外,在家電中嵌入ibeacon功能時,可以用major表示產品型號,用minor表示錯誤**,用來向外部通知故障。

ibeacon一項低耗能藍芽技術技術,工作原理類似之前的藍芽技術,由ibeacon發射訊號,ios裝置定位接受,反饋訊號。根據這項簡單的定位技術可以做出許多的相應技術應用。

#import "viewcontroller.h"

@inte***ce viewcontroller (

)@property

(nonatomic, strong)nsarray *beaconarr;

//存放掃瞄的ibeacon的陣列

@property

(nonatomic, strong)clbeaconregion *beacon;

//被掃瞄的ibeacon

@property

(nonatomic, strong)cllocationmanager *locationmanager;

@property

(nonatomic, strong)uitableview *tableview;

@property

(strong, nonatomic) cbperipheralmanager *peripheralmanager;

@property

(strong, nonatomic) nsdictionary *mybeacondata;

@end

@implementation viewcontroller-(

void

)viewdidload

}self

.peripheralmanager =

[[cbperipheralmanager alloc] initwithdelegate:

self

queue:nil

options:nil];}

-(void

)peripheralmanagerdidupdatestate:

(cbperipheralmanager *

)peripheral

else

if(peripheral.state == cbperipheralmanagerstatepoweredoff)}-

(void

)locationmanager:

(cllocationmanager *

)manager didchangeauthorizationstatus:

(clauthorizationstatus)status

}//發現有ibeacon進入檢測範圍-(

void

)locationmanager:

(cllocationmanager *

)manager didenterregion:

(clregion *

)region-(

void

)locationmanager:

(cllocationmanager*

)manager didexitregion:

(clregion*

)region

//找到ibeacon後掃瞄- (void)locationmanager:(cllocationmanager *)manager didrangebeacons:(nsarray*)beacons inregion:(clbeaconregion *)region

//列印所有的ibeacon的資訊

for(clbeacon *beacon in beacons)

_beaconarr = beacons;

[_tableview reloaddata];}

-(void

)locationmanager:

(cllocationmanager *

)manager monitoringdidfailforregion:

(clregion *

)region witherror:

(nserror *

)errorif(

(error.domain != kclerrordomain || error.code !=5)

&&[manager.monitoredregions containsobject:region])}

-(void

)locationmanager:

(cllocationmanager *

)manager didfailwitherror:

(nserror *

)error

-(nsinteger)tableview:

(uitableview *

)tableview numberofrowsinsection:

(nsinteger)section

-(uitableviewcell *

)tableview:

(uitableview *

)tableview cellforrowatindexpath:

(nsindexpath *

)indexpath

clbeacon *beacon =

[self

.beaconarr objectatindex:indexpath.row]

;cell.textlabel.text =

[beacon.proximityuuid uuidstring]

;nsstring *str;

switch

(beacon.proximity)

cell.detailtextlabel.text =

[nsstring stringwithformat:

@"%@ %ld %@ %@"

,str,beacon.rssi,beacon.major,beacon.minor]

;return cell;}-

(void

)didreceivememorywarning

@end

iOS藍芽開發

直接看 首先推薦去看官方文件哦 現將建立藍芽工程的要點總結一下,由於工程主要涉及中心模式,所以只總結中心模式的用法 1,引入corebluetooth.framework 2,實現藍芽協議,如 h檔案如下 protocol cbcentralmanagerdelegate protocol cbpe...

iOS藍芽開發

藍芽開發的流程 建立中心管理 cbcentralmanager 掃瞄外部裝置 連線外部裝置 掃瞄服務和特徵 資料互動 斷開連線 1 倒入 接下來的 如下 property nonatomic,strong cbperipheral peripheral 中心管家 property nonatomic...

iOS開發 GameKit藍芽開發

藍芽4.0是2012年最新藍芽版本,是3.0的公升級版本 較3.0版本更省電 成本低 3毫秒低延遲 超長有效連線距離 aes 128加密等 通常用在藍芽耳機 藍芽音箱等裝置上。藍芽技術聯盟 bluetooth sig 2010年7月7日宣布,正式採納藍芽4.0核心規範 bluetooth core ...