藍芽開發注意:
先定義中心裝置和外圍裝置以及遵守藍芽協議
@inte***ce viewcontroller()@property (strong, nonatomic) cbcentralmanager *manager;
@property (nonatomic, strong) cbperipheral *peripheral;
@property (nonatomic, weak)nstimer * connenttimer;
@end
判斷藍芽狀態,如成功則掃瞄指定uuid裝置(如不指定uuid,則無法後台持續連線)
當發現指定裝置後,連線該裝置
當連線指定外圍裝置成功,編寫定時器,每秒讀取1次rssi
當監聽到失去和外圍裝置連線,重新建立連線
當讀取到rssi值,列印出它的值
//藍芽狀態
- (void)centralmanagerdidupdatestate:(cbcentralmanager *)central
nslog(@"central manager state: %@", state);
}//查詢裝置
- (void)centralmanager:(cbcentralmanager *)central diddiscoverperipheral:(cbperipheral *)peripheral advertisementdata:(nsdictionary *)advertisementdata rssi:(nsnumber *)rssi
}- (void)connentperipheral
//連線成功後呼叫
- (void)centralmanager:(cbcentralmanager *)central didconnectperipheral:(cbperipheral *)peripheral
//當監聽到失去和外圍裝置連線,重新建立連線
//這個方法是必須實現的,因為藍芽會中斷連線,正好觸發這個方法重建連線。重建連線可能造成數秒後才能讀取到rssi。
- (void)centralmanager:(cbcentralmanager *)central diddisconnectperipheral:(cbperipheral *)peripheral error:(nserror *)error
- (void)centralmanager:(cbcentralmanager *)central didfailtoconnectperipheral:(cbperipheral *)peripheral error:(nserror *)error
//返回的藍芽服務通知通過**實現
- (void)peripheral:(cbperipheral *)peripheral diddiscoverservices:(nserror *)error
for (cbservice *service in peripheral.services)
}}//返回的藍芽特徵值通知通過**實現
- (void)peripheral:(cbperipheral *)peripheral diddiscovercharacteristicsforservice:(cbservice *)service error:(nserror *)error
for (cbcharacteristic * characteristic in service.characteristics)
}}//處理藍芽發過來的資料
- (void)peripheral:(cbperipheral *)peripheral didupdatevalueforcharacteristic:(cbcharacteristic *)characteristic error:(nserror *)error
-(void) notification:(cbuuid *) serviceuuid characteristicuuid:(cbuuid *)characteristicuuid peripheral:(cbperipheral *)p on:(bool)on
cbcharacteristic *characteristic = [self getcharacteristicfromuuid:characteristicuuid service:service];
if (!characteristic)
[p setnotifyvalue:on forcharacteristic:characteristic];
}-(cbservice *) getservicefromuuid:(cbuuid *)uuid p:(cbperipheral *)p
return nil; //service not found on this peripheral
}-(cbcharacteristic *) getcharacteristicfromuuid:(cbuuid *)uuid service:(cbservice*)service
return nil; //characteristic not found on this service
}
資料實時備份
隨著企業對資訊系統的依賴性越來越高,資料庫作為資訊系統的核心擔當著重要的角色。尤其在一些對資料可靠性要求很高的行業如銀行 電信等,如果發生意外停機或資料丟失其損失會十分慘重。資料庫的備份是乙個長期的過程,而恢復只在發生事故後進行,恢復可以看作是備份的逆過程,恢復的程度的好壞很大程度上依賴於備份的情況...
iOS藍芽開發
直接看 首先推薦去看官方文件哦 現將建立藍芽工程的要點總結一下,由於工程主要涉及中心模式,所以只總結中心模式的用法 1,引入corebluetooth.framework 2,實現藍芽協議,如 h檔案如下 protocol cbcentralmanagerdelegate protocol cbpe...
iOS藍芽開發
藍芽開發的流程 建立中心管理 cbcentralmanager 掃瞄外部裝置 連線外部裝置 掃瞄服務和特徵 資料互動 斷開連線 1 倒入 接下來的 如下 property nonatomic,strong cbperipheral peripheral 中心管家 property nonatomic...