Iphone 2个iOS设备之间的蓝牙连接
我正在尝试在iOS 5.0中引入。根据StackOverflow本身上的多个线程():Iphone 2个iOS设备之间的蓝牙连接,iphone,ios,bluetooth,core-bluetooth,bluetooth-lowenergy,Iphone,Ios,Bluetooth,Core Bluetooth,Bluetooth Lowenergy,我正在尝试在iOS 5.0中引入。根据StackOverflow本身上的多个线程(): 核心蓝牙框架可用于与任何 硬件,具有蓝牙低能耗(4.0)硬件支持 如果你愿意,我们可以忘记为iPhone/iPod(MFI)制作的程序 使用核心蓝牙技术 我随身带着iphone5、iphone4s、googleandroid nexus7,我确信至少前2款支持BLE 我的问题是 嗯,我在我的iPhone4S/iPhone5上尝试了下面给定的代码,但它没能扫描并找到旁边的iPhone5/iPhone4S。我可以
didiscoverperipal
从未被调用。
原因可能是什么?我错过什么了吗
这是我的代码(简化为一个小测试项目)
ViewController.h
正如spamsink评论的那样,一台设备需要充当外围设备,另一台设备需要充当中央设备,以便它们进行通信 苹果公司有一个很好的例子可以做到这一点。此外,请查看WWDC 2012第703和705次会议,了解有关CoreBooth框架使用的详细说明和示例
另外请注意,要使设备处于外围设备模式,需要将其更新为iOS 6.0或更高版本。嗯,我对蓝牙低能耗(BLE)的理解很差。正如公认的答案所指出的,一个设备必须充当中心设备,另一个设备必须充当外围设备,以便进行通信 iOS到iOS和iOS到Mac OS BLE通信的一个很好的示例源代码是 需要考虑的一些要点
还有一些信息。如果在didUpdateState委托中调用scanForPeripherals函数,那么它会工作,因为委托函数无法返回。几天后我将再次处理BLE。。。如果你还没有找到解决方案,我会看看是否能帮上忙。我对iPhone一无所知,但BLE的工作方式是,一台设备必须进行广播,以便另一台设备能够发现它。所以你需要两段不同的代码…@spamsink-hmm。。贴出这个问题后,我明白了这一点。。现在正在研究。。看来我对蓝牙通信的理解是业余的。。这似乎并不容易。。我会发回我发现的任何东西。示例应用程序和核心蓝牙将仅在使用Bluetooth 4.0的苹果产品上运行。下面是列表:有人尝试过示例源代码(CBPeripheralManager演示版)吗?它是否比上述答案中的“示例应用程序”更好?
@interface ViewController:UIViewController<CBCentralManagerDelegate, CBPeripheralDelegate{
}
@property (strong, nonatomic) CBCentralManager *mCentralManager;
@end
@implementation ViewController
@synthesize mCentralManager;
- (void)viewDidLoad{
[super viewDidLoad];
mCentralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
[self scanForPeripherals];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Received periferal :%@",peripheral);
}
- (int) scanForPeripherals {
if (self.mCentralManager.state != CBCentralManagerStatePoweredOn)
{
NSLog(@"self.mCentralManagerState : %d",self.mCentralManager.state);
return -1;
}
//Getting here alright.. bluetooth is powered on.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
//Documentation says passind nil as device UUID, scans and finds every peripherals
[self.mCentralManager scanForPeripheralsWithServices:nil options:options];
return 0;
}
@end