demo下载 http://download.csdn.net/detail/swibyn/9717588
直接看代码 http://blog.csdn.net/swibyn/article/details/53785249
首先推荐去看官方文档哦
现将创建蓝牙工程的要点总结一下,由于工程主要涉及中心模式,所以只总结中心模式的用法
1,引入CoreBluetooth.framework
2,实现蓝牙协议,如:
.h文件如下
@protocolCBCentralManagerDelegate;
@protocolCBPeripheralDelegate;
@interface ViewController :UIViewController <CBCentralManagerDelegate,CBPeripheralDelegate>
.m文件如下
#import "CoreBluetooth/CoreBluetooth.h"
另外还有代理部分请自行添加
3,下面是使蓝牙动起来的过程
3.1创建CBCentralManager实例
self.cbCentralMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
设置代理,比如:
self.cbCentralMgr.delegate =self;
创建数组管理外设
self.peripheralArray = [NSMutableArrayarray];