单军华
2018-04-20 2197e837490f5083d18d9fdb97265d1e0f04832a
pregnancy_guard/BaseProject/AppDelegate.m
@@ -19,6 +19,7 @@
#import "HomePage.h"
#import "SegmentedPage.h"
#import "CBMoralManager.h"
#import "SettingPage.h"
#import "PhotosPage.h"
#import "MinePage.h"
@@ -27,6 +28,9 @@
#import "HistoryRecordPage.h"
@interface AppDelegate ()
{
    NSMutableArray *notifyingCharacteristicsArray;
}
@property (nonatomic) Reachability *hostReachability;
@property (nonatomic) Reachability *internetReachability;
@@ -93,11 +97,10 @@
    // 要使用百度地图,请先启动BaiduMapManager
    self.mapManager = [[BMKMapManager alloc]init];
    BOOL ret = [self.mapManager start:@"HRr8jBYNgRoXgRGHyIg8oC1yYwIUk0IG" generalDelegate:self];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
//    BOOL ret = [self.mapManager start:@"ZiqQxvKGjZVNbITouYn7dIwDjb1CbKcy" generalDelegate:self];
//    if (!ret) {
//        NSLog(@"manager start failed!");
//    }
    
    // 添加网络监听
    self.hostReachability = [Reachability reachabilityWithHostName:@"www.baidu.com"];
@@ -107,9 +110,9 @@
    [self.internetReachability startNotifier];
    [self updateInterfaceWithReachability:self.internetReachability];
    
    //_currentDevice = _selectedDevice.mac;
    
    [self showHomePage2];
    [self showLoginPage];
    
    //异常对象:NSException
    //参数:将函数的地址给它
@@ -171,13 +174,50 @@
- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    if (!notifyingCharacteristicsArray)
    {
        notifyingCharacteristicsArray = [NSMutableArray array];
    }
    /* Stop notification of characteristics while enter in background */
    for (CBService *service in [[CBMoralManager sharedManager] foundServices])
    {
        for (CBCharacteristic *characteristic in service.characteristics)
        {
            if (characteristic.isNotifying  && ![characteristic.UUID isEqual:BOOT_LOADER_CHARACTERISTIC_UUID])
            {
                [[[CBMoralManager sharedManager] myPeripheral] setNotifyValue:NO forCharacteristic:characteristic];
                [notifyingCharacteristicsArray addObject:characteristic];
            }
        }
    }
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    /* Enable notification of characteristics while enter in foreground */
    if (notifyingCharacteristicsArray)
    {
        for (CBCharacteristic *characteristic in notifyingCharacteristicsArray)
        {
            if (![characteristic.UUID isEqual:BOOT_LOADER_CHARACTERISTIC_UUID])
            {
                [[[CBMoralManager sharedManager] myPeripheral] setNotifyValue:YES forCharacteristic:characteristic];
            }
        }
    }
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    NSLog(@"Registered to receive local notification...");
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
@@ -219,14 +259,13 @@
{
    
    //[UserDefault stringForKey:@"user_id"]
    NSString *path = [[NSString alloc] initWithFormat:GET_INFO];
    NSString *path = [[NSString alloc] initWithFormat:USER_GETINFO];
    
    CommonReqModel * model = [[CommonReqModel alloc] init];
    model.userID = [UserDefault stringForKey:@"user_id"];
    model.opt = [UserDefault stringForKey:@"opt"];
    model.phone = [UserDefault stringForKey:@"phone"];
    
    MPWeakSelf(self);
    [NetworkSingleton networkingPostMethod:model.toDic urlName:path success:^(id responseBody)
    [NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody)
     {
         MPStrongSelf(self);
         BaseResModel * resModel = [Global toBaseModel:responseBody];
@@ -244,15 +283,12 @@
                 // 存储用户信息
                 [UserDefault setObject:@"1" forKey:@"isLogin"];
                 [UserDefault setObject:userModel._id forKey:@"user_id"];
                 [UserDefault setObject:userModel.username forKey:@"username"];
                 [UserDefault setObject:userModel.phone forKey:@"phone"];
                 [UserDefault setObject:userModel.password forKey:@"password"];
                 [UserDefault setObject:userModel.nickname forKey:@"nickname"];
                 if(userModel.opt == 2)
                 {
                     [UserDefault setObject:userModel.hotel_id forKey:@"hotel_id"];
                 }
                  [UserDefault setObject:[NSString stringWithFormat:@"%d",userModel.opt] forKey:@"opt"];//opt=1表示运维人员,opt=2表示酒店前台
                 [UserDefault setObject:userModel.refresh_frequency forKey:@"refresh_frequency"];
                 [UserDefault setObject:userModel.is_open_upload forKey:@"is_open_upload"];
                 [UserDefault setObject:userModel.video forKey:@"video"];
                 [UserDefault synchronize];//使用synchronize强制立即将数据写入磁盘,防止在写完NSUserDefaults后程序退出导致的数据丢失
                 
                 // 跳转主界面
@@ -275,40 +311,6 @@
     {
         [UserDefault setObject:@"0" forKey:@"isLogin"];
         //[Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }];
}
//flr 默认 0
-(void) sendControl:(NSString*)device controlkey:(NSString*)key floor:(NSString*)flr funIndex:(NSString*)fun
{
//    NSString * device = @"f0fe6b156ebd";
//    NSString * key = @"7";
//    NSString * flr = [NSString stringWithFormat:@"%ld",row+1];
//    NSString * fun = [NSString stringWithFormat:@"%d",open == YES? 1:0];
    NSString *path = [[NSString alloc] initWithFormat:@"%@", [NSString stringWithFormat:Moral_Device_Url,device,key,flr,fun]];
    NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
    //MPWeakSelf(self);
    LOG_INFO(@"%@",path);
    [NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody)
     {
         //         BaseResModel * resModel = [Global toBaseModel:responseBody];
         //         if(resModel.code == 0)
         //         {
         //             [Global alertMessageEx:@"发送成功!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
         //             [weakself.navigationController popViewControllerAnimated:YES];
         //         }
         //         else
         //         {
         //             [Global alertMessageEx:resModel.desc title:@"发送失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
         //         }
     }
                                   failure:^(NSString *error)
     {
         [Global alertMessageEx:error title:@"发送失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
     }];
    
}