1
我正在測試一個應用程序來顯示附近的藍牙設備。現在,代碼簡單如下:iOS藍牙不發現設備
- (IBAction)scanForDevices:(id)sender
{
UIButton * btn = sender;
if(self.cManager.state != CBCentralManagerStatePoweredOn)
{
NSLog(@"CoreBluetooth is %s",[self centralManagerStateToString:self.cManager.state]);
}
if(!self.isSearching){
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[self.cManager scanForPeripheralsWithServices:nil options:options];
btn.titleLabel.text = @"Stop";
self.isSearching = YES;
}
else
{
btn.titleLabel.text = @"Search";
self.isSearching = NO;
}
}
#pragma mark - CBCentral Delegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSLog(@"Ready to discovery..");
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Receive periferal: %@", peripheral);
}
但每次我按下按鈕執行scanForDevices時間,回調函數接到電話,但與外圍空值。我不確定我的設備是否正常工作。在我的筆記本電腦上,我的iphone 4S(6.0.1)和ipad(7.1)都被發現,但不是來自iphone和ipad。
你必須從某個地方開始。問題#1是'我試圖發現的設備可以被發現嗎?'嘗試使用https://itunes.apple.com/us/app/lightblue-bluetooth-low-energy/id557428110?mt=8並告訴我們您是否可以真正看到設備。 – bsarrazin
顯然它沒有發現預期的設備。 '我想要發現的設備可以被發現是什麼意思?'如果我的MacBook可以發現我的iPhone和iPad,爲什麼不是其他方式或其他方式? – REALFREE
所以我的理解是,你試圖從你的iDevices中發現你的macbook?正確?當你打開藍牙設置(系統首選項 - >藍牙)時,你的MacBook才能被發現。如果你仔細看看他們的藍牙設置窗口,它會顯示「現在可以發現」爲你的macbook的名字「'」。否則,您的iBook設備將無法發現您的macbook。 – bsarrazin