MultipeerConnectivity 之蓝牙功能

南笙酒味 提交于 2019-12-15 17:34:34

步骤 手册一个广告,告诉别人,我的设备是可以被发现的的

扫描蓝牙设备,需要实现代理方法

实现一个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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!