步骤 手册一个广告,告诉别人,我的设备是可以被发现的的
扫描蓝牙设备,需要实现代理方法
实现一个MCSession对象存储当前,实现代理方法
实现MCSession对象,用来发送和接受数据
#import <MultipeerConnectivity/MultipeerConnectivity.h>
实现代理 MCBrowserViewControllerDelegate MCSessionDelegate
@property (nonatomic, strong)MCSession *m_session;
/** 发送广告 */
@property (nonatomic, strong) MCAdvertiserAssistant *assistant;
/** 当前连接到的设备 */
@property (nonatomic, strong) MCPeerID *peerId;
- (void)viewDidLoad {
[super viewDidLoad];
// 初始化 会话
// 获取设备的名字
NSString *displayName = [UIDevice currentDevice].name;
// 设备的id
MCPeerID *perrID = [[MCPeerID alloc]initWithDisplayName:displayName];
self.m_session = [[MCSession alloc]initWithPeer:perrID];
self.m_session.delegate = self;
}
// click events
- (IBAction)connect:(id)sender {
MCBrowserViewContro
来源:CSDN
作者:BianHuanShiZhe
链接:https://blog.csdn.net/BianHuanShiZhe/article/details/103549747