单军华
2018-04-28 1d39caf7235522ae121db7a188ba41a706217407
pregnancy_guard/BaseProject/Controller/Home/SearchDevicePage.m
@@ -15,8 +15,9 @@
#import "UIView+Toast.h"
#import "UIImage+animatedGIF.h"
#import "SearchTipsCell.h"
#import <CoreBluetooth/CoreBluetooth.h>
@interface SearchDevicePage ()<UITableViewDelegate,UITableViewDataSource>
@interface SearchDevicePage ()<UITableViewDelegate,UITableViewDataSource,CBCentralManagerDelegate>
{
    BOOL isBluetoothON;
    UIButton* ic_search_btn;
@@ -29,12 +30,48 @@
}
@property (nonatomic, strong) UITableView                   * tableView;
@property (nonatomic, assign) int                           currentStatus; // 0 初始化 1 检索中 2 检索完成
@property (nonatomic, strong) CBCentralManager              * centralManager;
@end
@implementation SearchDevicePage
//-(CBCentralManager *)centralManager
//{
//    if (_centralManager == nil) {
//        _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
//    }
//    return _centralManager;
//}
-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    switch (central.state) {
        case CBCentralManagerStatePoweredOff:
        {
            //[mainView makeToast:@"蓝牙没有开启,在设置中打开蓝牙"];
            [Global alertMessageEx:@"蓝牙没有开启,在设置中打开蓝牙功能" title:@"温馨提示" okTtitle:nil cancelTitle:@"OK" delegate:self];
        }
            break;
        case CBCentralManagerStatePoweredOn:
            NSLog(@"蓝牙设备开着");
            break;
        case CBCentralManagerStateResetting:
            break;
        case CBCentralManagerStateUnauthorized:
            break;
        case CBCentralManagerStateUnknown:
            break;
        case CBCentralManagerStateUnsupported:
            NSLog(@"当前设备不支持蓝牙");
            [Global alertMessageEx:@"很抱歉,当前设备不支持蓝牙" title:@"温馨提示" okTtitle:nil cancelTitle:@"OK" delegate:self];
            break;
        default:
            break;
    }
}
- (UITableView *)tableView
{
    if (!_tableView)
@@ -61,7 +98,7 @@
{
    [super viewDidAppear:animated];
    [[CBMoralManager sharedManager] disconnectPeripheral:[[CBMoralManager sharedManager] myPeripheral]];
    
}
@@ -114,10 +151,12 @@
    
    ic_top_bkH = 325;
    ic_search_doneH = 230;
    CGFloat btnSearchH = 55;
    if ( IsiPhone4 || IsiPhone5 )
    {
        ic_top_bkH = 260;
        ic_search_doneH = 180;
        btnSearchH = 40;
    }
    
    UIImageView * ic_top_bk = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ic_top_bkH)];
@@ -134,7 +173,7 @@
    ic_searching.hidden = YES;
    
    ic_search_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    ic_search_btn.frame = CGRectMake((SCREEN_WIDTH-128)/2, ic_search_doneH+55, 128, 32);
    ic_search_btn.frame = CGRectMake((SCREEN_WIDTH-128)/2, ic_search_doneH+btnSearchH, 128, 32);
    [ic_search_btn setBackgroundImage:[UIImage imageNamed:@"ic_search_start_btn" ] forState:UIControlStateNormal];
    ic_search_btn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    ic_search_btn.layer.masksToBounds=YES;
@@ -144,6 +183,8 @@
    
    self.tableView.hidden = NO;
    // Do any additional setup after loading the view.
    self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
    
    [[CBMoralManager sharedManager] setCbDiscoveryDelegate:self];
}
@@ -204,7 +245,7 @@
            _SetTitleLabel.text = @"操作设置步骤";
            
            return cell;
        }
        else
        {
@@ -292,10 +333,10 @@
            
            //[cell setDiscoveredPeripheralDataFromPeripheral:newPeriPheral];
            
           return cell;
            return cell;
        }
    }
    return  nil;
}
@@ -367,28 +408,28 @@
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
     if (_currentStatus == 2)
     {
          NSInteger index = [indexPath row];
         if (isBluetoothON)
         {
             [tableView deselectRowAtIndexPath:indexPath animated:YES];
             [self connectPeripheral:indexPath.row];
         }
         // DeviceSpareModel* model = [self.modelArray objectAtIndex:index];
         // 跳转酒店备用界面
         //HotelSelPage* page = [[HotelSelPage alloc] initIsFirstPage:NO];
         //page.bSelRoom = 2;
         // 跳转界面
         //BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page];
         //[self presentViewController:baseNav animated:YES completion:nil];
         //[self showActionForPhoto];
     }
    
    if (_currentStatus == 2)
    {
        NSInteger index = [indexPath row];
        if (isBluetoothON)
        {
            [tableView deselectRowAtIndexPath:indexPath animated:YES];
            [self connectPeripheral:indexPath.row];
        }
        // DeviceSpareModel* model = [self.modelArray objectAtIndex:index];
        // 跳转酒店备用界面
        //HotelSelPage* page = [[HotelSelPage alloc] initIsFirstPage:NO];
        //page.bSelRoom = 2;
        // 跳转界面
        //BaseNaviController *baseNav = [[BaseNaviController alloc] initWithRootViewController:page];
        //[self presentViewController:baseNav animated:YES completion:nil];
        //[self showActionForPhoto];
    }
}
@@ -449,7 +490,7 @@
                [UserDefault setObject:bleUUID forKey:@"bleUUID"];
                [UserDefault setObject:bleName forKey:@"bleName"];
                
                [UserDefault synchronize];//使用synchronize强制立即将数据写入磁盘,防止在写完NSUserDefaults后程序退出导致的数据丢失
                [UserDefault synchronize];//使用synchronize强制立即将数据写入磁盘,防止在写完NSUserDefaults后程序退出导致的数据丢失
                //CBPeripheralExt *selBLE = [UserDefault objectForKey:@"Peripheral"];//根据键值取出Peripheral
                [self backAticon];
            }
@@ -508,13 +549,14 @@
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 #pragma mark - Navigation
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
@end