为什么使用coreBluetooth connectPeripheral没有在IOS8中调用委托方法 [英] Why use coreBluetooth connectPeripheral did not call delegate methods in IOS8
问题描述
我想在 IOS8 中使用 CoreBluetooth.framework 来实现数据传输,我确实在以下方法中发现了外设并尝试连接外围设备。
I want use CoreBluetooth.framework in IOS8 to achieve data transfer, i did discover peripheral in the follow method and try connect the peripheral.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Discover name : %@", peripheral.name);
[self.centralManager connectPeripheral:peripheral options:nil];
}
但它没有调用委托方法 didFailToConnectPeripheral 或者 didConnectPeripheral ,我对它有什么问题,是代码错误还是IOS8需要一些额外的东西?如何处理,请提前感谢!
But it did not call the delegate methods didFailToConnectPeripheral or didConnectPeripheral , I waner what's wrong with it, is the code error or IOS8 need some extra things ? How to deal it, thank in advance!
这是我在 github中的代码,我写了一个程序服务器,另一个程序是中心。
here is my code in github ,I write a Program to be server and another be Central.
推荐答案
@Sj评论为我解决了它,复制它如果有人会错过它,请回答:
@Sj comment solved it for me, copying it into an answer in case someone will miss it:
您是否尝试将外围物体存放在ivar中然后连接到它?即self.discoveredPeripheral = peripheral; [self.centralManager connectPeripheral:self.discoveredPeripheral options:nil];
Did u tried storing the peripheral object in an ivar and then connect to it? ie self.discoveredPeripheral = peripheral; [self.centralManager connectPeripheral:self.discoveredPeripheral options:nil];
这篇关于为什么使用coreBluetooth connectPeripheral没有在IOS8中调用委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!