Commit 771a085a authored by lujunye's avatar lujunye

调整登录状态

parent 1029702b
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<key>GeliBusinessPlatform.xcscheme_^#shared#^_</key> <key>GeliBusinessPlatform.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>23</integer> <integer>22</integer>
</dict> </dict>
</dict> </dict>
</dict> </dict>
......
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
#import "MJRefresh.h" #import "MJRefresh.h"
#import "WYHead.h" #import "WYHead.h"
#endif /* Bridge_Header_h */ #endif /* Bridge_Header_h */
This diff is collapsed.
This diff is collapsed.
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief babybluetooth 的block定义和储存
*/
// Created by 刘彦玮 on 15/9/2.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import <CoreBluetooth/CoreBluetooth.h>
#import "BabyOptions.h"
//设备状态改变的委托
typedef void (^BBCentralManagerDidUpdateStateBlock)(CBCentralManager *central);
//找到设备的委托
typedef void (^BBDiscoverPeripheralsBlock)(CBCentralManager *central,CBPeripheral *peripheral,NSDictionary *advertisementData, NSNumber *RSSI);
//连接设备成功的block
typedef void (^BBConnectedPeripheralBlock)(CBCentralManager *central,CBPeripheral *peripheral);
//连接设备失败的block
typedef void (^BBFailToConnectBlock)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error);
//断开设备连接的bock
typedef void (^BBDisconnectBlock)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error);
//找到服务的block
typedef void (^BBDiscoverServicesBlock)(CBPeripheral *peripheral,NSError *error);
//找到Characteristics的block
typedef void (^BBDiscoverCharacteristicsBlock)(CBPeripheral *peripheral,CBService *service,NSError *error);
//更新(获取)Characteristics的value的block
typedef void (^BBReadValueForCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSError *error);
//获取Characteristics的名称
typedef void (^BBDiscoverDescriptorsForCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *service,NSError *error);
//获取Descriptors的值
typedef void (^BBReadValueForDescriptorsBlock)(CBPeripheral *peripheral,CBDescriptor *descriptor,NSError *error);
//babyBluettooth cancelScanBlock方法调用后的回调
typedef void (^BBCancelScanBlock)(CBCentralManager *centralManager);
//babyBluettooth cancelAllPeripheralsConnection 方法调用后的回调
typedef void (^BBCancelAllPeripheralsConnectionBlock)(CBCentralManager *centralManager);
typedef void (^BBDidWriteValueForCharacteristicBlock)(CBCharacteristic *characteristic,NSError *error);
typedef void (^BBDidWriteValueForDescriptorBlock)(CBDescriptor *descriptor,NSError *error);
typedef void (^BBDidUpdateNotificationStateForCharacteristicBlock)(CBCharacteristic *characteristic,NSError *error);
typedef void (^BBDidReadRSSIBlock)(NSNumber *RSSI,NSError *error);
typedef void (^BBDidDiscoverIncludedServicesForServiceBlock)(CBService *service,NSError *error);
typedef void (^BBDidUpdateNameBlock)(CBPeripheral *peripheral);
typedef void (^BBDidModifyServicesBlock)(CBPeripheral *peripheral,NSArray *invalidatedServices);
//peripheral model
typedef void (^BBPeripheralModelDidUpdateState)(CBPeripheralManager *peripheral);
typedef void (^BBPeripheralModelDidAddService)(CBPeripheralManager *peripheral,CBService *service,NSError *error);
typedef void (^BBPeripheralModelDidStartAdvertising)(CBPeripheralManager *peripheral,NSError *error);
typedef void (^BBPeripheralModelDidReceiveReadRequest)(CBPeripheralManager *peripheral,CBATTRequest *request);
typedef void (^BBPeripheralModelDidReceiveWriteRequests)(CBPeripheralManager *peripheral,NSArray *requests);
typedef void (^BBPeripheralModelDidSubscribeToCharacteristic)(CBPeripheralManager *peripheral,CBCentral *central,CBCharacteristic *characteristic);
typedef void (^BBPeripheralModelDidUnSubscribeToCharacteristic)(CBPeripheralManager *peripheral,CBCentral *central,CBCharacteristic *characteristic);
@interface BabyCallback : NSObject
#pragma mark - callback block
//设备状态改变的委托
@property (nonatomic, copy) BBCentralManagerDidUpdateStateBlock blockOnCentralManagerDidUpdateState;
//发现peripherals
@property (nonatomic, copy) BBDiscoverPeripheralsBlock blockOnDiscoverPeripherals;
//连接callback
@property (nonatomic, copy) BBConnectedPeripheralBlock blockOnConnectedPeripheral;
//连接设备失败的block
@property (nonatomic, copy) BBFailToConnectBlock blockOnFailToConnect;
//断开设备连接的bock
@property (nonatomic, copy) BBDisconnectBlock blockOnDisconnect;
//发现services
@property (nonatomic, copy) BBDiscoverServicesBlock blockOnDiscoverServices;
//发现Characteristics
@property (nonatomic, copy) BBDiscoverCharacteristicsBlock blockOnDiscoverCharacteristics;
//发现更新Characteristics的
@property (nonatomic, copy) BBReadValueForCharacteristicBlock blockOnReadValueForCharacteristic;
//获取Characteristics的名称
@property (nonatomic, copy) BBDiscoverDescriptorsForCharacteristicBlock blockOnDiscoverDescriptorsForCharacteristic;
//获取Descriptors的值
@property (nonatomic,copy) BBReadValueForDescriptorsBlock blockOnReadValueForDescriptors;
@property (nonatomic, copy) BBDidWriteValueForCharacteristicBlock blockOnDidWriteValueForCharacteristic;
@property (nonatomic, copy) BBDidWriteValueForDescriptorBlock blockOnDidWriteValueForDescriptor;
@property (nonatomic, copy) BBDidUpdateNotificationStateForCharacteristicBlock blockOnDidUpdateNotificationStateForCharacteristic;
@property (nonatomic, copy) BBDidReadRSSIBlock blockOnDidReadRSSI;
@property (nonatomic, copy) BBDidDiscoverIncludedServicesForServiceBlock blockOnDidDiscoverIncludedServicesForService;
@property (nonatomic, copy) BBDidUpdateNameBlock blockOnDidUpdateName;
@property (nonatomic, copy) BBDidModifyServicesBlock blockOnDidModifyServices;
//babyBluettooth stopScan方法调用后的回调
@property(nonatomic,copy) BBCancelScanBlock blockOnCancelScan;
//babyBluettooth stopConnectAllPerihperals 方法调用后的回调
@property(nonatomic,copy) BBCancelAllPeripheralsConnectionBlock blockOnCancelAllPeripheralsConnection;
//babyBluettooth 蓝牙使用的参数参数
@property(nonatomic,strong) BabyOptions *babyOptions;
#pragma mark - 过滤器Filter
//发现peripherals规则
@property (nonatomic, copy) BOOL (^filterOnDiscoverPeripherals)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI);
//连接peripherals规则
@property (nonatomic, copy) BOOL (^filterOnconnectToPeripherals)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI);
#pragma mark - peripheral model
//peripheral model
@property (nonatomic, copy) BBPeripheralModelDidUpdateState blockOnPeripheralModelDidUpdateState;
@property (nonatomic, copy) BBPeripheralModelDidAddService blockOnPeripheralModelDidAddService;
@property (nonatomic, copy) BBPeripheralModelDidStartAdvertising blockOnPeripheralModelDidStartAdvertising;
@property (nonatomic, copy) BBPeripheralModelDidReceiveReadRequest blockOnPeripheralModelDidReceiveReadRequest;
@property (nonatomic, copy) BBPeripheralModelDidReceiveWriteRequests blockOnPeripheralModelDidReceiveWriteRequests;
@property (nonatomic, copy) BBPeripheralModelDidSubscribeToCharacteristic blockOnPeripheralModelDidSubscribeToCharacteristic;
@property (nonatomic, copy) BBPeripheralModelDidUnSubscribeToCharacteristic blockOnPeripheralModelDidUnSubscribeToCharacteristic;
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
*/
// Created by 刘彦玮 on 15/9/2.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import "BabyCallback.h"
@implementation BabyCallback
- (instancetype)init {
self = [super init];
if (self) {
[self setFilterOnDiscoverPeripherals:^BOOL(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI) {
if (![peripheralName isEqualToString:@""]) {
return YES;
}
return NO;
}];
[self setFilterOnconnectToPeripherals:^BOOL(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI) {
if (![peripheralName isEqualToString:@""]) {
return YES;
}
return NO;
}];
}
return self;
}
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief 蓝牙中心模式实现类
*/
// Created by 刘彦玮 on 15/7/30.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "BabyToy.h"
#import "BabySpeaker.h"
#import "BabyDefine.h"
@interface BabyCentralManager : NSObject<CBCentralManagerDelegate,CBPeripheralDelegate> {
@public
//方法是否处理
BOOL needScanForPeripherals;//是否扫描Peripherals
BOOL needConnectPeripheral;//是否连接Peripherals
BOOL needDiscoverServices;//是否发现Services
BOOL needDiscoverCharacteristics;//是否获取Characteristics
BOOL needReadValueForCharacteristic;//是否获取(更新)Characteristics的值
BOOL needDiscoverDescriptorsForCharacteristic;//是否获取Characteristics的描述
BOOL needReadValueForDescriptors;//是否获取Descriptors的值
//一次性处理
BOOL oneReadValueForDescriptors;
//方法执行时间
int executeTime;
NSTimer *connectTimer;
//pocket
NSMutableDictionary *pocket;
//主设备
CBCentralManager *centralManager;
//回叫方法
BabySpeaker *babySpeaker;
@private
//已经连接的设备
NSMutableArray *connectedPeripherals;
//已经连接的设备
NSMutableArray *discoverPeripherals;
//需要自动重连的外设
NSMutableArray *reConnectPeripherals;
}
//扫描Peripherals
- (void)scanPeripherals;
//连接Peripherals
- (void)connectToPeripheral:(CBPeripheral *)peripheral;
//断开设备连接
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;
//断开所有已连接的设备
- (void)cancelAllPeripheralsConnection;
//停止扫描
- (void)cancelScan;
//获取当前连接的peripherals
- (NSArray *)findConnectedPeripherals;
//获取当前连接的peripheral
- (CBPeripheral *)findConnectedPeripheral:(NSString *)peripheralName;
/**
sometimes ever,sometimes never. 相聚有时,后会无期
this is center with peripheral's story
**/
//sometimes ever:添加断开重连接的设备
- (void)sometimes_ever:(CBPeripheral *)peripheral ;
//sometimes never:删除需要重连接的设备
- (void)sometimes_never:(CBPeripheral *)peripheral ;
@end
This diff is collapsed.
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief 预定义一些库的执行行为和配置
*/
// Created by 刘彦玮 on 6/4/19.
// Copyright © 2016年 liuyanwei. All rights reserved.
//
#import <Foundation/Foundation.h>
# pragma mark - baby 行为定义
//Baby if show log 是否打印日志,默认1:打印 ,0:不打印
#define KBABY_IS_SHOW_LOG 1
//CBcentralManager等待设备打开次数
# define KBABY_CENTRAL_MANAGER_INIT_WAIT_TIMES 5
//CBcentralManager等待设备打开间隔时间
# define KBABY_CENTRAL_MANAGER_INIT_WAIT_SECOND 2.0
//BabyRhythm默认心跳时间间隔
#define KBABYRHYTHM_BEATS_DEFAULT_INTERVAL 3;
//Baby默认链式方法channel名称
#define KBABY_DETAULT_CHANNEL @"babyDefault"
# pragma mark - baby通知
//蓝牙系统通知
//centralManager status did change notification
#define BabyNotificationAtCentralManagerDidUpdateState @"BabyNotificationAtCentralManagerDidUpdateState"
//did discover peripheral notification
#define BabyNotificationAtDidDiscoverPeripheral @"BabyNotificationAtDidDiscoverPeripheral"
//did connection peripheral notification
#define BabyNotificationAtDidConnectPeripheral @"BabyNotificationAtDidConnectPeripheral"
//did filed connect peripheral notification
#define BabyNotificationAtDidFailToConnectPeripheral @"BabyNotificationAtDidFailToConnectPeripheral"
//did disconnect peripheral notification
#define BabyNotificationAtDidDisconnectPeripheral @"BabyNotificationAtDidDisconnectPeripheral"
//did discover service notification
#define BabyNotificationAtDidDiscoverServices @"BabyNotificationAtDidDiscoverServices"
//did discover characteristics notification
#define BabyNotificationAtDidDiscoverCharacteristicsForService @"BabyNotificationAtDidDiscoverCharacteristicsForService"
//did read or notify characteristic when received value notification
#define BabyNotificationAtDidUpdateValueForCharacteristic @"BabyNotificationAtDidUpdateValueForCharacteristic"
//did write characteristic and response value notification
#define BabyNotificationAtDidWriteValueForCharacteristic @"BabyNotificationAtDidWriteValueForCharacteristic"
//did change characteristis notify status notification
#define BabyNotificationAtDidUpdateNotificationStateForCharacteristic @"BabyNotificationAtDidUpdateNotificationStateForCharacteristic"
//did read rssi and receiced value notification
#define BabyNotificationAtDidReadRSSI @"BabyNotificationAtDidReadRSSI"
//蓝牙扩展通知
// did centralManager enable notification
#define BabyNotificationAtCentralManagerEnable @"BabyNotificationAtCentralManagerEnable"
# pragma mark - baby 定义的方法
//Baby log
#define BabyLog(fmt, ...) if(KBABY_IS_SHOW_LOG) { NSLog(fmt,##__VA_ARGS__); }
@interface BabyDefine : NSObject
@end
//
// BabyBlueDefine.m
// BabyTestProject
//
// Created by xuanyan.lyw on 16/4/19.
// Copyright © 2016年 liuyanwei. All rights reserved.
//
#import "BabyDefine.h"
@implementation BabyDefine
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief babybluetooth 封装蓝牙外设模式的运行时参数,可以实现后台模式,重复接收广播,查找service参数,查找characteristic参数
*/
// Created by 刘彦玮 on 15/9/27.
// Copyright © 2015年 刘彦玮. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface BabyOptions : NSObject
#pragma mark - 属性
/*!
* 扫描参数,centralManager:scanForPeripheralsWithServices:self.scanForPeripheralsWithServices options:self.scanForPeripheralsWithOptions
* @param An optional dictionary specifying options for the scan.
* @see centralManager:scanForPeripheralsWithServices
* @seealso CBCentralManagerScanOptionAllowDuplicatesKey :忽略同一个Peripheral端的多个发现事件被聚合成一个发现事件
* @seealso CBCentralManagerScanOptionSolicitedServiceUUIDsKey
*/
@property (nonatomic, copy) NSDictionary *scanForPeripheralsWithOptions;
/*!
* 连接设备的参数
* @method connectPeripheral:options:
* @param An optional dictionary specifying connection behavior options.
* @see centralManager:didConnectPeripheral:
* @see centralManager:didFailToConnectPeripheral:error:
* @seealso CBConnectPeripheralOptionNotifyOnConnectionKey
* @seealso CBConnectPeripheralOptionNotifyOnDisconnectionKey
* @seealso CBConnectPeripheralOptionNotifyOnNotificationKey
*/
@property (nonatomic, copy) NSDictionary *connectPeripheralWithOptions;
/*!
* 扫描参数,centralManager:scanForPeripheralsWithServices:self.scanForPeripheralsWithServices options:self.scanForPeripheralsWithOptions
*@param serviceUUIDs A list of <code>CBUUID</code> objects representing the service(s) to scan for.
*@see centralManager:scanForPeripheralsWithServices
*/
@property (nonatomic, copy) NSArray *scanForPeripheralsWithServices;
// [peripheral discoverServices:self.discoverWithServices];
@property (nonatomic, copy) NSArray *discoverWithServices;
// [peripheral discoverCharacteristics:self.discoverWithCharacteristics forService:service];
@property (nonatomic, copy) NSArray *discoverWithCharacteristics;
#pragma mark - 构造方法
- (instancetype)initWithscanForPeripheralsWithOptions:(NSDictionary *)scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *)connectPeripheralWithOptions;
- (instancetype)initWithscanForPeripheralsWithOptions:(NSDictionary *)scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *)connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;
@end
//
// BabyClothes.m
// BabyBluetoothAppDemo
//
// Created by 刘彦玮 on 15/9/27.
// Copyright © 2015年 刘彦玮. All rights reserved.
//
#import "BabyOptions.h"
@implementation BabyOptions
- (instancetype)init {
self = [super init];
if (self) {
_scanForPeripheralsWithOptions = nil;
_connectPeripheralWithOptions = nil;
_scanForPeripheralsWithServices = nil;
_discoverWithServices = nil;
_discoverWithCharacteristics = nil;
}
return self;
}
- (instancetype)initWithscanForPeripheralsWithOptions:(NSDictionary *)scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *)connectPeripheralWithOptions
{
self = [super init];
if (self) {
[self setScanForPeripheralsWithOptions:scanForPeripheralsWithOptions];
[self setConnectPeripheralWithOptions:connectPeripheralWithOptions];
}
return self;
}
- (instancetype)initWithscanForPeripheralsWithOptions:(NSDictionary *)scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *)connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics
{
self = [self initWithscanForPeripheralsWithOptions:scanForPeripheralsWithOptions connectPeripheralWithOptions:connectPeripheralWithOptions];
if (self) {
[self setScanForPeripheralsWithServices:scanForPeripheralsWithServices];
[self setDiscoverWithServices:discoverWithServices];
[self setDiscoverWithCharacteristics:discoverWithCharacteristics];
}
return self;
}
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief 蓝牙外设模式实现类
*/
// Created by 刘彦玮 on 15/12/12.
// Copyright © 2015年 刘彦玮. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "BabyToy.h"
#import "BabySpeaker.h"
@interface BabyPeripheralManager : NSObject<CBPeripheralManagerDelegate> {
@public
//回叫方法
BabySpeaker *babySpeaker;
}
/**
添加服务
*/
- (BabyPeripheralManager *(^)(NSArray *array))addServices;
/**
启动广播
*/
- (BabyPeripheralManager *(^)())startAdvertising;
//外设管理器
@property (nonatomic, strong) CBPeripheralManager *peripheralManager;
@property (nonatomic, copy) NSString *localName;
@property (nonatomic, strong) NSMutableArray *services;
@end
/**
* 构造Characteristic,并加入service
* service:CBService
* param`ter for properties :option 'r' | 'w' | 'n' or combination
* r CBCharacteristicPropertyRead
* w CBCharacteristicPropertyWrite
* n CBCharacteristicPropertyNotify
* default value is rw Read-Write
* paramter for descriptor:be uesd descriptor for characteristic
*/
void makeCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *properties,NSString *descriptor);
/**
* 构造一个包含初始值的Characteristic,并加入service,包含了初值的characteristic必须设置permissions和properties都为只读
* make characteristic then add to service, a static characteristic mean it has a initial value .according apple rule, it must set properties and permissions to CBCharacteristicPropertyRead and CBAttributePermissionsReadable
*/
void makeStaticCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *descriptor,NSData *data);
/**
生成CBService
*/
CBMutableService* makeCBService(NSString *UUID);
/**
生成UUID
*/
NSString* genUUID();
//
// BabyPeripheralManager.m
// BluetoothStubOnIOS
//
// Created by 刘彦玮 on 15/12/12.
// Copyright © 2015年 刘彦玮. All rights reserved.
//
#import "BabyPeripheralManager.h"
#import "BabyDefine.h"
#define callbackBlock(...) if ([[babySpeaker callback] __VA_ARGS__]) [[babySpeaker callback] __VA_ARGS__ ]
@implementation BabyPeripheralManager {
int PERIPHERAL_MANAGER_INIT_WAIT_TIMES;
int didAddServices;
NSTimer *addServiceTask;
}
- (instancetype)init {
self = [super init];
if (self) {
_localName = @"baby-default-name";
_peripheralManager = [[CBPeripheralManager alloc]initWithDelegate:self queue:nil options:nil];
}
return self;
}
- (BabyPeripheralManager *(^)())startAdvertising {
return ^BabyPeripheralManager *() {
if ([self canStartAdvertising]) {
PERIPHERAL_MANAGER_INIT_WAIT_TIMES = 0;
NSMutableArray *UUIDS = [NSMutableArray array];
for (CBMutableService *s in _services) {
[UUIDS addObject:s.UUID];
}
//启动广播
[_peripheralManager startAdvertising:
@{
CBAdvertisementDataServiceUUIDsKey : UUIDS
,CBAdvertisementDataLocalNameKey : _localName
}];
}
else {
PERIPHERAL_MANAGER_INIT_WAIT_TIMES++;
if (PERIPHERAL_MANAGER_INIT_WAIT_TIMES > 5) {
BabyLog(@">>>error: 第%d次等待peripheralManager打开任然失败,请检查蓝牙设备是否可用",PERIPHERAL_MANAGER_INIT_WAIT_TIMES);
}
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 3.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
self.startAdvertising();
});
BabyLog(@">>> 第%d次等待peripheralManager打开",PERIPHERAL_MANAGER_INIT_WAIT_TIMES);
}
return self;
};
}
- (BOOL)canStartAdvertising {
if (_peripheralManager.state != CBPeripheralManagerStatePoweredOn) {
return NO;
}
if (didAddServices != _services.count) {
return NO;
}
return YES;
}
- (BOOL)isPoweredOn {
if (_peripheralManager.state != CBPeripheralManagerStatePoweredOn) {
return NO;
}
return YES;
}
- (BabyPeripheralManager *(^)(NSArray *array))addServices {
return ^BabyPeripheralManager*(NSArray *array) {
_services = [NSMutableArray arrayWithArray:array];
[self addServicesToPeripheral];
return self;
};
}
- (void)addServicesToPeripheral {
if ([self isPoweredOn]) {
for (CBMutableService *s in _services) {
[_peripheralManager addService:s];
}
}
else {
[addServiceTask setFireDate:[NSDate distantPast]];
addServiceTask = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(addServicesToPeripheral) userInfo:nil repeats:NO];
}
}
#pragma mark - peripheralManager delegate
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
switch (peripheral.state) {
case CBPeripheralManagerStateUnknown:
BabyLog(@">>>CBPeripheralManagerStateUnknown");
break;
case CBPeripheralManagerStateResetting:
BabyLog(@">>>CBPeripheralManagerStateResetting");
break;
case CBPeripheralManagerStateUnsupported:
BabyLog(@">>>CBPeripheralManagerStateUnsupported");
break;
case CBPeripheralManagerStateUnauthorized:
BabyLog(@">>>CBPeripheralManagerStateUnauthorized");
break;
case CBPeripheralManagerStatePoweredOff:
BabyLog(@">>>CBPeripheralManagerStatePoweredOff");
break;
case CBPeripheralManagerStatePoweredOn:
BabyLog(@">>>CBPeripheralManagerStatePoweredOn");
//发送centralManagerDidUpdateState通知
[[NSNotificationCenter defaultCenter]postNotificationName:@"CBPeripheralManagerStatePoweredOn" object:nil];
break;
default:
break;
}
// if([babySpeaker callback] blockOnPeripheralModelDidUpdateState) {
// [currChannel blockOnCancelScan](centralManager);
// }
callbackBlock(blockOnPeripheralModelDidUpdateState)(peripheral);
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral didAddService:(CBService *)service error:(NSError *)error {
didAddServices++;
callbackBlock(blockOnPeripheralModelDidAddService)(peripheral,service,error);
}
- (void)peripheralManagerDidStartAdvertising:(CBPeripheralManager *)peripheral error:(NSError *)error {
callbackBlock(blockOnPeripheralModelDidStartAdvertising)(peripheral,error);
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveReadRequest:(CBATTRequest *)request {
callbackBlock(blockOnPeripheralModelDidReceiveReadRequest)(peripheral, request);
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests {
callbackBlock(blockOnPeripheralModelDidReceiveWriteRequests)(peripheral,requests);
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic {
callbackBlock(blockOnPeripheralModelDidSubscribeToCharacteristic)(peripheral,central,characteristic);
}
- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didUnsubscribeFromCharacteristic:(CBCharacteristic *)characteristic {
callbackBlock(blockOnPeripheralModelDidUnSubscribeToCharacteristic)(peripheral,central,characteristic);
}
@end
void makeCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *properties,NSString *descriptor) {
//paramter for properties
CBCharacteristicProperties prop = 0x00;
if ([properties containsString:@"r"]) {
prop = prop | CBCharacteristicPropertyRead;
}
if ([properties containsString:@"w"]) {
prop = prop | CBCharacteristicPropertyWrite;
}
if ([properties containsString:@"n"]) {
prop = prop | CBCharacteristicPropertyNotify;
}
if (properties == nil || [properties isEqualToString:@""]) {
prop = CBCharacteristicPropertyRead | CBCharacteristicPropertyWrite;
}
CBMutableCharacteristic *c = [[CBMutableCharacteristic alloc]initWithType:[CBUUID UUIDWithString:UUID] properties:prop value:nil permissions:CBAttributePermissionsReadable | CBAttributePermissionsWriteable];
//paramter for descriptor
if (!(descriptor == nil || [descriptor isEqualToString:@""])) {
//c设置description对应的haracteristics字段描述
CBUUID *CBUUIDCharacteristicUserDescriptionStringUUID = [CBUUID UUIDWithString:CBUUIDCharacteristicUserDescriptionString];
CBMutableDescriptor *desc = [[CBMutableDescriptor alloc]initWithType: CBUUIDCharacteristicUserDescriptionStringUUID value:descriptor];
[c setDescriptors:@[desc]];
}
if (!service.characteristics) {
service.characteristics = @[];
}
NSMutableArray *cs = [service.characteristics mutableCopy];
[cs addObject:c];
service.characteristics = [cs copy];
}
void makeStaticCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *descriptor,NSData *data) {
CBMutableCharacteristic *c = [[CBMutableCharacteristic alloc]initWithType:[CBUUID UUIDWithString:UUID] properties:CBCharacteristicPropertyRead value:data permissions:CBAttributePermissionsReadable];
//paramter for descriptor
if (!(descriptor == nil || [descriptor isEqualToString:@""])) {
//c设置description对应的haracteristics字段描述
CBUUID *CBUUIDCharacteristicUserDescriptionStringUUID = [CBUUID UUIDWithString:CBUUIDCharacteristicUserDescriptionString];
CBMutableDescriptor *desc = [[CBMutableDescriptor alloc]initWithType: CBUUIDCharacteristicUserDescriptionStringUUID value:descriptor];
[c setDescriptors:@[desc]];
}
if (!service.characteristics) {
service.characteristics = @[];
}
NSMutableArray *cs = [service.characteristics mutableCopy];
[cs addObject:c];
service.characteristics = [cs copy];
}
CBMutableService* makeCBService(NSString *UUID)
{
CBMutableService *s = [[CBMutableService alloc]initWithType:[CBUUID UUIDWithString:UUID] primary:YES];
return s;
}
NSString * genUUID()
{
CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid = [NSString stringWithString:(__bridge NSString*)uuid_string_ref];
CFRelease(uuid_string_ref);
return uuid;
}
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief babybluetooth Rhythm用于检测蓝牙的任务执行情况,处理复杂的蓝牙流程操作
*/
//
// Created by ZTELiuyw on 15/9/15.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "BabyDefine.h"
@interface BabyRhythm : NSObject
typedef void (^BBBeatsBreakBlock)(BabyRhythm *bry);
typedef void (^BBBeatsOverBlock)(BabyRhythm *bry);
//timer for beats
@property (nonatomic, strong) NSTimer *beatsTimer;
//beat interval
@property NSInteger beatsInterval;
#pragma mark beats
//心跳
- (void)beats;
//主动中断心跳
- (void)beatsBreak;
//结束心跳,结束后会进入BlockOnBeatOver,并且结束后再不会在触发BlockOnBeatBreak
- (void)beatsOver;
//恢复心跳,beatsOver操作后可以使用beatsRestart恢复心跳,恢复后又可以进入BlockOnBeatBreak方法
- (void)beatsRestart;
//心跳中断的委托
- (void)setBlockOnBeatsBreak:(void(^)(BabyRhythm *bry))block;
//心跳结束的委托
- (void)setBlockOnBeatsOver:(void(^)(BabyRhythm *bry))block;
@end
//
// BabyBeats.m
// BabyBluetoothAppDemo
//
// Created by ZTELiuyw on 15/9/15.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import "BabyRhythm.h"
#import "BabyDefine.h"
@implementation BabyRhythm {
BOOL isOver;
BBBeatsBreakBlock blockOnBeatBreak;
BBBeatsOverBlock blockOnBeatOver;
}
- (instancetype)init {
self = [super init];
if (self) {
//beatsInterval
_beatsInterval = KBABYRHYTHM_BEATS_DEFAULT_INTERVAL;
}
return self;
}
- (void)beats {
if (isOver) {
BabyLog(@">>>beats isOver");
return;
}
BabyLog(@">>>beats at :%@",[NSDate date]);
if (self.beatsTimer) {
[self.beatsTimer setFireDate: [[NSDate date]dateByAddingTimeInterval:self.beatsInterval]];
}
else {
self.beatsTimer = [NSTimer timerWithTimeInterval:self.beatsInterval target:self selector:@selector(beatsBreak) userInfo:nil repeats:YES];
[self.beatsTimer setFireDate: [[NSDate date]dateByAddingTimeInterval:self.beatsInterval]];
[[NSRunLoop currentRunLoop] addTimer:self.beatsTimer forMode:NSRunLoopCommonModes];
}
}
- (void)beatsBreak {
BabyLog(@">>>beatsBreak :%@",[NSDate date]);
[self.beatsTimer setFireDate:[NSDate distantFuture]];
if (blockOnBeatBreak) {
blockOnBeatBreak(self);
}
}
- (void)beatsOver {
BabyLog(@">>>beatsOver :%@",[NSDate date]);
[self.beatsTimer setFireDate:[NSDate distantFuture]];
isOver = YES;
if (blockOnBeatOver) {
blockOnBeatOver(self);
}
}
- (void)beatsRestart {
BabyLog(@">>>beatsRestart :%@",[NSDate date]);
isOver = NO;
[self beats];
}
- (void)setBlockOnBeatsBreak:(void(^)(BabyRhythm *bry))block {
blockOnBeatBreak = block;
}
- (void)setBlockOnBeatsOver:(void(^)(BabyRhythm *bry))block {
blockOnBeatOver = block;
}
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief babybluetooth block查找和channel切换
*/
// Created by 刘彦玮 on 15/9/2.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import "BabyCallback.h"
#import <CoreBluetooth/CoreBluetooth.h>
@interface BabySpeaker : NSObject
- (BabyCallback *)callback;
- (BabyCallback *)callbackOnCurrChannel;
- (BabyCallback *)callbackOnChnnel:(NSString *)channel;
- (BabyCallback *)callbackOnChnnel:(NSString *)channel
createWhenNotExist:(BOOL)createWhenNotExist;
//切换频道
- (void)switchChannel:(NSString *)channel;
//添加到notify list
- (void)addNotifyCallback:(CBCharacteristic *)c
withBlock:(void(^)(CBPeripheral *peripheral, CBCharacteristic *characteristics, NSError *error))block;
//添加到notify list
- (void)removeNotifyCallback:(CBCharacteristic *)c;
//获取notify list
- (NSMutableDictionary *)notifyCallBackList;
//获取notityBlock
- (void(^)(CBPeripheral *peripheral, CBCharacteristic *characteristics, NSError *error))notifyCallback:(CBCharacteristic *)c;
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
*/
// Created by 刘彦玮 on 15/9/2.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import "BabySpeaker.h"
#import "BabyDefine.h"
typedef NS_ENUM(NSUInteger, BabySpeakerType) {
BabySpeakerTypeDiscoverPeripherals,
BabySpeakerTypeConnectedPeripheral,
BabySpeakerTypeDiscoverPeripheralsFailToConnect,
BabySpeakerTypeDiscoverPeripheralsDisconnect,
BabySpeakerTypeDiscoverPeripheralsDiscoverServices,
BabySpeakerTypeDiscoverPeripheralsDiscoverCharacteristics,
BabySpeakerTypeDiscoverPeripheralsReadValueForCharacteristic,
BabySpeakerTypeDiscoverPeripheralsDiscoverDescriptorsForCharacteristic,
BabySpeakerTypeDiscoverPeripheralsReadValueForDescriptorsBlock
};
@implementation BabySpeaker {
//所有委托频道
NSMutableDictionary *channels;
//当前委托频道
NSString *currChannel;
//notifyList
NSMutableDictionary *notifyList;
}
- (instancetype)init {
self = [super init];
if (self) {
BabyCallback *defaultCallback = [[BabyCallback alloc]init];
notifyList = [[NSMutableDictionary alloc]init];
channels = [[NSMutableDictionary alloc]init];
currChannel = KBABY_DETAULT_CHANNEL;
[channels setObject:defaultCallback forKey:KBABY_DETAULT_CHANNEL];
}
return self;
}
- (BabyCallback *)callback {
return [channels objectForKey:KBABY_DETAULT_CHANNEL];
}
- (BabyCallback *)callbackOnCurrChannel {
return [self callbackOnChnnel:currChannel];
}
- (BabyCallback *)callbackOnChnnel:(NSString *)channel {
if (!channel) {
[self callback];
}
return [channels objectForKey:channel];
}
- (BabyCallback *)callbackOnChnnel:(NSString *)channel
createWhenNotExist:(BOOL)createWhenNotExist {
BabyCallback *callback = [channels objectForKey:channel];
if (!callback && createWhenNotExist) {
callback = [[BabyCallback alloc]init];
[channels setObject:callback forKey:channel];
}
return callback;
}
- (void)switchChannel:(NSString *)channel {
if (channel) {
if ([self callbackOnChnnel:channel]) {
currChannel = channel;
BabyLog(@">>>已切换到%@",channel);
}
else {
BabyLog(@">>>所要切换的channel不存在");
}
}
else {
currChannel = KBABY_DETAULT_CHANNEL;
BabyLog(@">>>已切换到默认频道");
}
}
//添加到notify list
- (void)addNotifyCallback:(CBCharacteristic *)c
withBlock:(void(^)(CBPeripheral *peripheral, CBCharacteristic *characteristics, NSError *error))block {
[notifyList setObject:block forKey:c.UUID.description];
}
//添加到notify list
- (void)removeNotifyCallback:(CBCharacteristic *)c {
[notifyList removeObjectForKey:c.UUID.description];
}
//获取notify list
- (NSMutableDictionary *)notifyCallBackList {
return notifyList;
}
//获取notityBlock
- (void(^)(CBPeripheral *peripheral, CBCharacteristic *characteristics, NSError *error))notifyCallback:(CBCharacteristic *)c {
return [notifyList objectForKey:c.UUID.description];
}
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
@brief babybluetooth 工具类
*/
// Created by 刘彦玮 on 15/8/1.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface BabyToy : NSObject
//十六进制转换为普通字符串的。
+ (NSString *)ConvertHexStringToString:(NSString *)hexString;
//普通字符串转换为十六进制
+ (NSString *)ConvertStringToHexString:(NSString *)string;
//int转data
+(NSData *)ConvertIntToData:(int)i;
//data转int
+(int)ConvertDataToInt:(NSData *)data;
//十六进制转换为普通字符串的。
+ (NSData *)ConvertHexStringToData:(NSString *)hexString;
//根据UUIDString查找CBCharacteristic
+(CBCharacteristic *)findCharacteristicFormServices:(NSMutableArray *)services
UUIDString:(NSString *)UUIDString;
@end
/*
BabyBluetooth
简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
https://github.com/coolnameismy/BabyBluetooth
*/
// Created by 刘彦玮 on 15/8/1.
// Copyright (c) 2015年 刘彦玮. All rights reserved.
//
#import "BabyToy.h"
@implementation BabyToy
//十六进制转换为普通字符串的。
+ (NSString *)ConvertHexStringToString:(NSString *)hexString {
char *myBuffer = (char *)malloc((int)[hexString length] / 2 + 1);
bzero(myBuffer, [hexString length] / 2 + 1);
for (int i = 0; i < [hexString length] - 1; i += 2) {
unsigned int anInt;
NSString * hexCharStr = [hexString substringWithRange:NSMakeRange(i, 2)];
NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
[scanner scanHexInt:&anInt];
myBuffer[i / 2] = (char)anInt;
}
NSString *unicodeString = [NSString stringWithCString:myBuffer encoding:4];
// BabyLog(@"===字符串===%@",unicodeString);
return unicodeString;
}
//普通字符串转换为十六进制
+ (NSString *)ConvertStringToHexString:(NSString *)string {
NSData *myD = [string dataUsingEncoding:NSUTF8StringEncoding];
Byte *bytes = (Byte *)[myD bytes];
//下面是Byte 转换为16进制。
NSString *hexStr=@"";
for (int i=0;i<[myD length];i++) {
NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16进制数
if ([newHexStr length]==1) {
hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
}
else{
hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
}
}
return hexStr;
}
//int转data
+ (NSData *)ConvertIntToData:(int)i {
NSData *data = [NSData dataWithBytes: &i length: sizeof(i)];
return data;
}
//data转int
+ (int)ConvertDataToInt:(NSData *)data {
int i;
[data getBytes:&i length:sizeof(i)];
return i;
}
//十六进制转换为普通字符串的。
+ (NSData *)ConvertHexStringToData:(NSString *)hexString {
NSData *data = [[BabyToy ConvertHexStringToString:hexString] dataUsingEncoding:NSUTF8StringEncoding];
return data;
}
//根据UUIDString查找CBCharacteristic
+ (CBCharacteristic *)findCharacteristicFormServices:(NSMutableArray *)services
UUIDString:(NSString *)UUIDString {
for (CBService *s in services) {
for (CBCharacteristic *c in s.characteristics) {
if ([c.UUID.UUIDString isEqualToString:UUIDString]) {
return c;
}
}
}
return nil;
}
@end
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import UIKit import UIKit
import Alamofire import Alamofire
import CryptoSwift import CryptoSwift
import LGButton
class LoginViewController: BaseViewController { class LoginViewController: BaseViewController {
...@@ -31,6 +31,7 @@ self.navigationController?.pushViewController(vc, animated: true) ...@@ -31,6 +31,7 @@ self.navigationController?.pushViewController(vc, animated: true)
self.navigationController?.pushViewController(vc, animated: true) self.navigationController?.pushViewController(vc, animated: true)
} }
//MARK: - 输入账号、密码、验证码 //MARK: - 输入账号、密码、验证码
@IBOutlet weak var loginBtn: LGButton!
@IBOutlet weak var codeView: UIView! @IBOutlet weak var codeView: UIView!
@IBOutlet weak var phoneTF: UITextField! @IBOutlet weak var phoneTF: UITextField!
@IBOutlet weak var passTF: UITextField! @IBOutlet weak var passTF: UITextField!
...@@ -60,6 +61,9 @@ self.navigationController?.pushViewController(vc, animated: true) ...@@ -60,6 +61,9 @@ self.navigationController?.pushViewController(vc, animated: true)
make.left.right.equalTo(0) make.left.right.equalTo(0)
make.height.equalTo(60) make.height.equalTo(60)
} }
//登录中状态
// loginBtn.isLoading = true
} }
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<outlet property="bannerImg" destination="AdE-4p-9iF" id="Eub-F8-pfv"/> <outlet property="bannerImg" destination="AdE-4p-9iF" id="Eub-F8-pfv"/>
<outlet property="codeTF" destination="qfV-go-Nf1" id="dsy-cS-dte"/> <outlet property="codeTF" destination="qfV-go-Nf1" id="dsy-cS-dte"/>
<outlet property="codeView" destination="dgy-iq-Edz" id="6HM-ez-mXt"/> <outlet property="codeView" destination="dgy-iq-Edz" id="6HM-ez-mXt"/>
<outlet property="loginBtn" destination="I08-S6-beg" id="bDZ-w8-CrS"/>
<outlet property="passTF" destination="ipW-Al-eG6" id="P2q-AH-6SO"/> <outlet property="passTF" destination="ipW-Al-eG6" id="P2q-AH-6SO"/>
<outlet property="phoneTF" destination="xEL-ml-rz8" id="wzo-Rz-RWS"/> <outlet property="phoneTF" destination="xEL-ml-rz8" id="wzo-Rz-RWS"/>
<outlet property="shBtn" destination="xgv-CB-GLZ" id="3XV-lQ-3ja"/> <outlet property="shBtn" destination="xgv-CB-GLZ" id="3XV-lQ-3ja"/>
...@@ -257,6 +258,10 @@ ...@@ -257,6 +258,10 @@
<real key="value" value="17"/> <real key="value" value="17"/>
</userDefinedRuntimeAttribute> </userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="titleFontName" value="PingFang SC Medium"/> <userDefinedRuntimeAttribute type="string" keyPath="titleFontName" value="PingFang SC Medium"/>
<userDefinedRuntimeAttribute type="string" keyPath="loadingString" value="登录中"/>
<userDefinedRuntimeAttribute type="number" keyPath="loadingFontSize">
<real key="value" value="17"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes> </userDefinedRuntimeAttributes>
<connections> <connections>
<action selector="loginAction:" destination="-1" eventType="touchUpInside" id="jlC-gq-qwQ"/> <action selector="loginAction:" destination="-1" eventType="touchUpInside" id="jlC-gq-qwQ"/>
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
<key>SVProgressHUD.xcscheme_^#shared#^_</key> <key>SVProgressHUD.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>22</integer> <integer>21</integer>
</dict> </dict>
<key>SkeletonView.xcscheme</key> <key>SkeletonView.xcscheme</key>
<dict> <dict>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment