当前位置: 首页 > news >正文

沧州网络营销网络宣传业务seo在哪可以学

沧州网络营销网络宣传业务,seo在哪可以学,广东新闻联播,个人网站怎么申请注册iOS开发蓝牙功能主要分扫描中心和外设设备 Central: 中心设备,发起蓝牙连接的设备(一般指手机)Peripheral: 外设,被蓝牙连接的设备(一般是运动手环/蓝牙模块)Service:服务,每个设备会提供服务,一个设备有很多服务Characteristic:特征,每个服务中包含很多个特征,这些特征的权限…iOS开发蓝牙功能主要分扫描中心和外设设备 Central: 中心设备,发起蓝牙连接的设备(一般指手机)Peripheral: 外设,被蓝牙连接的设备(一般是运动手环/蓝牙模块)Service:服务,每个设备会提供服务,一个设备有很多服务Characteristic:特征,每个服务中包含很多个特征,这些特征的权限一般分为:读(read)/写(write)/通知(notice)几种,可以通过特征进行读写数据(重要角色)(中心设备写入数据的时候一定要找到可写入特征才可以写入成功)Descriptor:描述者,每个特征可以对应一个或者多个描述者,用于描述特征的信息或者属性 准备工作iOS设备接入#import CoreBluetooth/CoreBluetooth.h一台手机作为中心设备一台手机作为外设(或者蓝牙设备硬件)外安装一个蓝牙调试助手作为辅助工具查找那些特征是可写可读等等。 以下是流程代码 1.中心设备开启扫描调用即可[self mCentral]; - (CBCentralManager *)mCentral {if (!_mCentral) {_mCentral [[CBCentralManager alloc] initWithDelegate:selfqueue:dispatch_get_main_queue()options:nil];}return _mCentral; }2.中心设备初始化后调用以下代理方法必须实现的 //2、只要中心管理者初始化,就会触发此代理方法 - (void)centralManagerDidUpdateState:(CBCentralManager *)central {switch (central.state) {case CBManagerStateUnknown:NSLog(CBCentralManagerStateUnknown);break;case CBManagerStateResetting:NSLog(CBCentralManagerStateResetting);break;case CBManagerStateUnsupported:NSLog(CBCentralManagerStateUnsupported);break;case CBManagerStateUnauthorized:NSLog(CBCentralManagerStateUnauthorized);break;case CBManagerStatePoweredOff:NSLog(CBCentralManagerStatePoweredOff);break;case CBManagerStatePoweredOn:{NSLog(CBCentralManagerStatePoweredOn);//3、搜索外设[self.mCentral scanForPeripheralsWithServices:nil // 通过某些服务筛选外设options:nil]; // dict,条件}break;default:break;} } 3.发现外部设备后(蓝牙设备)的回调方法 //4、发现外设后调用的方法 - (void)centralManager:(CBCentralManager *)central // 中心管理者didDiscoverPeripheral:(CBPeripheral *)peripheral // 外设advertisementData:(NSDictionary *)advertisementData // 外设携带的数据RSSI:(NSNumber *)RSSI // 外设发出的蓝牙信号强度 {if (peripheral.name) {[self.dataArr addObject:peripheral];}[self.tableView reloadData];//(ABS(RSSI.integerValue) 35)//5、发现完之后就是进行连接if([peripheral.name isEqualToString:mBLEName]){self.mPeripheral peripheral;self.mPeripheral.delegate self;[self.mCentral connectPeripheral:peripheral options:nil];} }4.确定要连接哪个蓝牙设备(我这里用的是tableView显示发现的外部蓝牙设备所以在这个代理方法里面点击具体某个设备即可) - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{CBPeripheral *per self.dataArr[indexPath.row];self.mPeripheral per;self.mPeripheral.delegate self;[self.mCentral connectPeripheral:per options:nil]; }5.中心设备链接外部设备成功失败丢失的回调方法如果需要自动重连可以失败丢失接口里面重新调用连接 //6、中心管理者连接外设成功 - (void)centralManager:(CBCentralManager *)central // 中心管理者didConnectPeripheral:(CBPeripheral *)peripheral // 外设 {NSLog(%设备连接成功, peripheral.name);//7、外设发现服务,传nil代表不过滤[self.mPeripheral discoverServices:nil]; }// 外设连接失败 - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {NSLog(设备连接失败%, peripheral.name); }// 丢失连接 - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {NSLog(设备丢失连接%, peripheral.name); } 6.连接蓝牙成功以后实现以下回调查找我们需要的特征跟进具体某个特征是否可写可读进行记录后续作为写入和读取数据使用(查询是否可写可读时可以手机安装一个蓝牙调试助手查看) //8、发现外设的服务后调用的方法 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {// 是否获取失败if (error) {NSLog(备获取服务失败%, peripheral.name);return;}for (CBService *service in peripheral.services) {self.mService service;NSLog(发现外设的服务后调用的方法 设备的服务%,UUID%,count%lu,service,service.UUID,peripheral.services.count);//9、外设发现特征[peripheral discoverCharacteristics:nil forService:service];} }//10、发现外设特征的时候调用的代理方法 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {//这里面校验哪些特征值是可写或者可读 这里可以使用手机端搜索蓝牙调试助手查看哪些特征服务可写for (CBCharacteristic *cha in service.characteristics) {if([cha.UUID.UUIDString isEqualToString:8667556C-9A37-4C91-84ED-54EE27D90049]){//找到可写的特征self.mCharacteristic cha;NSLog(从服务中发现外设特征的时候调用的代理方法设备的服务%,服务对应的特征值%,UUID%---%,,service,cha,cha.UUID,cha.UUID.UUIDString);//11、获取特征对应的描述 会回调didUpdateValueForDescriptor[peripheral discoverDescriptorsForCharacteristic:cha];//12、获取特征的值 会回调didUpdateValueForCharacteristic[peripheral readValueForCharacteristic:cha];//打开外设的通知否则无法接受数据[peripheral setNotifyValue:YES forCharacteristic:self.mCharacteristic];}}}//13、更新描述值的时候会调用 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error {NSLog(描述%,descriptor.description); }//14、更新特征值的时候调用可以理解为获取蓝牙发回的数据 获取外设发来的数据,不论是read和notify,获取数据都从这个方法中读取 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {NSData* data characteristic.value;NSString* value [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];NSLog(uuid:% value : %,characteristic.UUID,value); }//15、通知状态改变时调用 -(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{if(error){NSLog(改变通知状态);} }//16、发现外设的特征的描述数组 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error {// 在此处读取描述即可for (CBDescriptor *descriptor in characteristic.descriptors) {self.mDescriptor descriptor;NSLog(发现外设的特征descriptor%,descriptor);} }7。写入数据以及写入失败成功回调(写入数据时候的特征一定要是可写的特征这个上一步那里可以知道) //17、发送数据 - (void)send{// 核心代码在这里[self.mPeripheral writeValue:[写数据 dataUsingEncoding:NSUTF8StringEncoding]// 写入的数据forCharacteristic:self.mCharacteristic // 写给哪个特征这个特征必须是可写特征才能写入成功因为一个蓝牙外设可以有很多个服务很多特征type:CBCharacteristicWriteWithResponse];// 通过此响应记录是否成功写入 }//向peripheral中写入数据后的回调函数 - (void)peripheral:(CBPeripheral*)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{if (error) {NSLog(写入失败%,error);return;}NSLog(write value success(写入成功) : %%, characteristic,[[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]); }到此中心设备相关实现就完成了如果是跟蓝牙硬件交互只需要跟硬件相关人员协调写入数据和读取数据的各种格式以及写入哪个特征等等即可 以下是外部设备相关实现也就是如果把手机作为外设时候的代码实现 1.定义外设初始化外设相关名称代码 interface NoticePeripheraManagerViewController ()CBPeripheralManagerDelegate property (nonatomic, strong) CBPeripheralManager *peripheralManager; property (nonatomic, strong) UILabel *statusL; property (strong, nonatomic) NSData *dataToSend; property (nonatomic, strong) CBMutableCharacteristic *cumCharacteristic; end- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor [UIColor whiteColor];self.statusL [[UILabel alloc] initWithFrame:self.view.bounds];self.statusL.textColor [UIColor blackColor];self.statusL.font [UIFont systemFontOfSize:18];self.statusL.numberOfLines 0;[self.view addSubview:self.statusL];/*和CBCentralManager类似蓝牙设备打开需要一定时间打开成功后会进入委托方法- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral;模拟器永远也不会得CBPeripheralManagerStatePoweredOn状态*/self.peripheralManager [[CBPeripheralManager alloc]initWithDelegate:self queue:nil];// 初始化数据self.dataToSend [snadjfkhaw加大困难的是咖啡euijferlfmn ksxncjxznvjeajfrnjadnfjasfndsafnjsadkfnjsa dataUsingEncoding:NSUTF8StringEncoding]; } //peripheralManager状态改变 - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{switch (peripheral.state) {//在这里判断蓝牙设别的状态 当开启了则可调用 setUp方法(自定义)case CBManagerStatePoweredOn:NSLog(powered on);self.statusL.text [NSString stringWithFormat:设备名%已经打开可以使用center进行连接,ios设备];[self setUp];break;case CBManagerStatePoweredOff:NSLog(powered off);self.statusL.text powered off;break;default:break;} }- (void)setUp{/*typedef NS_OPTIONS(NSUInteger, CBAttributePermissions) {CBAttributePermissionsReadable 0x01, //可读CBAttributePermissionsWriteable 0x02, //可写CBAttributePermissionsReadEncryptionRequired 0x04, //可读需要建立安全连接CBAttributePermissionsWriteEncryptionRequired 0x08 // //可写需要建立安全连接} NS_ENUM_AVAILABLE(10_9, 6_0);*/CBMutableCharacteristic *writeReadCharacteristic [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:FF01] properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyWrite value:nil permissions:CBCharacteristicPropertyRead | CBCharacteristicPropertyWrite];CBMutableService *service [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:FF66] primary:YES];[service setCharacteristics:[writeReadCharacteristic]];self.cumCharacteristic writeReadCharacteristic;[self.peripheralManager addService:service];}//添加了服务回调 - (void)peripheralManager:(CBPeripheralManager *)peripheral didAddService:(CBService *)service error:(NSError *)error{NSLog(添加服务成功开始广播);[self.peripheralManager startAdvertising:{CBAdvertisementDataServiceUUIDsKey:[[CBUUID UUIDWithString:FF66]],CBAdvertisementDataLocalNameKey:ios设备}]; }//当中央端连接上了此设备并订阅了特征时会回调 didSubscribeToCharacteristic: - (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic {NSLog(当中央端连接上了此设备并订阅了特征时会回调);[self.peripheralManager updateValue:[订阅特征 dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:characteristic onSubscribedCentrals:nil]; }//当接收到中央端读的请求时会调用didReceiveReadRequest: - (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveReadRequest:(CBATTRequest *)request {if (request.characteristic.properties CBCharacteristicPropertyRead) {NSData *data [收到读的请求 dataUsingEncoding:NSUTF8StringEncoding];self.statusL.text 收到读的请求;[request setValue:data];[self.peripheralManager respondToRequest:request withResult:CBATTErrorSuccess];} else {[self.peripheralManager respondToRequest:request withResult:CBATTErrorReadNotPermitted];} }- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests {self.statusL.text 收到写的请求;NSData *res [[NSString stringWithFormat:Hello] dataUsingEncoding:NSUTF8StringEncoding];[self.peripheralManager updateValue:resforCharacteristic:self.cumCharacteristiconSubscribedCentrals:nil]; }
http://www.huolong8.cn/news/274095/

相关文章:

  • 网站的营销功能公司做网站找谁公司做网站找谁
  • 揭阳东莞网站建设建站宝盒手机版下载
  • c 网站开发宿迁华夏建设集团网站
  • 网站悬浮代码社交电商十大平台有哪些
  • 网站源码下载软件中国移动网络优化做什么的
  • 做app还是做网站合适6昆明建设局网站号码
  • 做特产的网站开张怎么宣传wordpress视频适应手机
  • 长春网站建设加q479185700东莞常平建网站公司
  • 商城网站建设公司哪家好网站建设开发计划
  • 城乡互动联盟网站建设南宁百度seo排名优化
  • linux 国外网站手机大型网站
  • asp网站安装到空间宁夏建设工程招标投标管理中心网站
  • 本地网站建设教程xampp今天最新生猪价格
  • 交互设计包含网站设计网站开发常用图标
  • 可以免费建设网站网页模板网站有哪些
  • 网站开发基本流程图营销型网站的重要特点
  • wordpress电影站主题新网站一般多久收录
  • 北京好一点的微网站开发公司怎么做淘客手机网站
  • 网站建设怎么搞网站界面设计需要首先做市场研究
  • 有个域名怎样做网站专门做汽车内饰的网站
  • 最好在线网站建设p2p是什么意思
  • 腾讯云wordpress搭建网站开发软件属于什么行业
  • 网站建设的费是多少做的最好的微电影网站有哪些
  • 网站建设服务协议伦教网站建设
  • 鹿泉企业网站建设网站建设源码导入
  • 大良用户网站建设世界工业设计大学排名前25
  • 襄阳专业做网站o2o网站建设技术
  • 厦门 网站建设 公司酒仙网网站推广方式
  • 如何制作单页网站德兴网站seo
  • 网站建设合同 代码应不应该给百度一下知道首页