iOS開發登入頁面的實現

weixin_34194087發表於2016-04-11

LoginViewController.h


#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController<UITextFieldDelegate>

- (IBAction)loginBtnAction:(id)sender;

@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *passTextField;
@property (weak, nonatomic) IBOutlet UITextField *unitTextField;

@end

LoginViewController.m

#import "LoginViewController.h"
#import <ProtocolBuffers/ProtocolBuffers.h>
#import "ApiM.pb.h"
#import "PBHttpMethod.h"
#import <MRProgress.h>
#import "DDMenuController.h"
#import "FitHeader.h"
#import "ZhexianView.h"
#import "JPUSHService.h"
#import "DXAlertView.h"
#import "CoreDataManager.h"
#import "Fun.h"
#import "RootTabBarController.h"
#import "PersonInfoLeftViewController.h"
@interface LoginViewController ()<UITextFieldDelegate, UITabBarControllerDelegate>
@property(nonatomic, strong)CoreDataManager *manager;
@property(nonatomic, strong)Fun *fun;
@property(nonatomic, assign)NSInteger keyboardHeight;
@property(nonatomic, assign)BOOL keyboardIsShow;
@property(nonatomic, strong)UITextField *userTextField;
@property(nonatomic, strong)UITextField *passTextField;
@property(nonatomic, strong)UITextField *unitTextField;
@property(nonatomic, strong)UIButton *loginButton;
@property(nonatomic, strong)UIImageView *userInputBackImageView;
@property(nonatomic, strong)UIImageView *passwordInputBackImageView;
@property(nonatomic, strong)UIImageView *unitInputBackImageView;
@property(nonatomic, strong)MRProgressOverlayView *progressView;
//@property(nonatomic, strong)MBProgressHUD *progressView;
@end
static NSString *const URLPATH = @"http://demo.xxxx.xx/xxx/";

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0.76 green:0.64 blue:0.49 alpha:1];
    _manager = [CoreDataManager shareManager];
    
    //圖示
    UIImageView *iconIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 255/4 * FitWidth, 80 * FitHeight, 255/2 * FitWidth, 269/2 * FitHeight)];
    iconIamgeView.image = [UIImage imageNamed:@"登入_03"];
    [self.view addSubview:iconIamgeView];
    //名稱
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(iconIamgeView.frame.origin.x, iconIamgeView.frame.origin.y + iconIamgeView.frame.size.height, iconIamgeView.frame.size.width, 40 * FitHeight)];
    nameLabel.text = @"00";
    nameLabel.font = [UIFont systemFontOfSize:25];
    nameLabel.textAlignment = 1;
    nameLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:nameLabel];
    //使用者名稱
    UIImageView *userBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(70 * FitWidth, nameLabel.frame.origin.y + nameLabel.frame.size.height + 100 * FitHeight, 526/2 * FitWidth, 92/2 * FitHeight)];
    userBackImageView.userInteractionEnabled = YES;
    userBackImageView.image = [UIImage imageNamed:@"登sss錄_07"];
    [self.view addSubview:userBackImageView];
    
    _userInputBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * FitWidth, 5 * FitHeight, 499/2 * FitWidth, 70/2 * FitHeight)];
    _userInputBackImageView.userInteractionEnabled = YES;
    _userInputBackImageView.image = [UIImage imageNamed:@"登sss錄_03"];
    [userBackImageView addSubview:_userInputBackImageView];
    _userInputBackImageView.hidden = YES;

    
    UIImageView *userIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-10 * FitWidth, 8 * FitHeight, 56/2 * FitWidth, 56/2 * FitWidth)];
    userIconImageView.image = [UIImage imageNamed:@"登入_07"];
    [userBackImageView addSubview:userIconImageView];
    
    _userTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, userBackImageView.frame.size.width, userBackImageView.frame.size.height)];
    [userBackImageView addSubview:_userTextField];
    
    //密碼
    UIImageView *passwordBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(userBackImageView.frame.origin.x, userBackImageView.frame.origin.y + userBackImageView.frame.size.height + 20 * FitHeight, userBackImageView.frame.size.width, userBackImageView.frame.size.height)];
    passwordBackImageView.userInteractionEnabled = YES;
    passwordBackImageView.image = [UIImage imageNamed:@"登sss錄_07"];
    [self.view addSubview:passwordBackImageView];
    
    _passwordInputBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * FitWidth, 5 *FitHeight, 499/2 * FitWidth, 70/2 * FitHeight)];
    _passwordInputBackImageView.userInteractionEnabled = YES;
    _passwordInputBackImageView.image = [UIImage imageNamed:@"登sss錄_03"];
    [passwordBackImageView addSubview:_passwordInputBackImageView];
    _passwordInputBackImageView.hidden = YES;
    
    UIImageView *passwordIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(userIconImageView.frame.origin.x, userIconImageView.frame.origin.y, userIconImageView.frame.size.width, userIconImageView.frame.size.height)];
    passwordIconImageView.image = [UIImage imageNamed:@"登入_10"];
    [passwordBackImageView addSubview:passwordIconImageView];
    
    _passTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, passwordBackImageView.frame.size.width, passwordBackImageView.frame.size.height)];
    _passTextField.secureTextEntry = YES;
    [passwordBackImageView addSubview:_passTextField];
    //單位識別碼
    UIImageView *unitBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(passwordBackImageView.frame.origin.x, passwordBackImageView.frame.origin.y + passwordBackImageView.frame.size.height + 20 * FitHeight, passwordBackImageView.frame.size.width, passwordBackImageView.frame.size.height)];
    unitBackImageView.userInteractionEnabled = YES;
    unitBackImageView.image = [UIImage imageNamed:@"登sss錄_07"];
    [self.view addSubview:unitBackImageView];
    
    _unitInputBackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * FitWidth, 5 * FitHeight, 499/2 *FitWidth, 70/2 * FitHeight)];
    _unitInputBackImageView.userInteractionEnabled = YES;
    _unitInputBackImageView.image = [UIImage imageNamed:@"登sss錄_03"];
    [unitBackImageView addSubview:_unitInputBackImageView];
    _unitInputBackImageView.hidden = YES;
    
    UIImageView *unitIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(passwordIconImageView.frame.origin.x, passwordIconImageView.frame.origin.y, passwordIconImageView.frame.size.width, passwordIconImageView.frame.size.height)];
    unitIconImageView.image = [UIImage imageNamed:@"登入_12"];
    [unitBackImageView addSubview:unitIconImageView];
    
    _unitTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, unitBackImageView.frame.size.width, unitBackImageView.frame.size.height)];
    [unitBackImageView addSubview:_unitTextField];
    //登入
    _loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _loginButton.frame = CGRectMake(unitBackImageView.frame.origin.x - 10 * FitWidth, unitBackImageView.frame.origin.y + passwordBackImageView.frame.size.height + 20 * FitHeight, unitBackImageView.frame.size.width, unitBackImageView.frame.size.height);
    _loginButton.backgroundColor = [UIColor colorWithRed:0.59 green:0.42 blue:0.24 alpha:1];
    [_loginButton setTitle:@"登入" forState:UIControlStateNormal];
    _loginButton.layer.cornerRadius = 25 * FitWidth;
    [_loginButton setTitleColor:[UIColor colorWithRed:0.94 green:0.76 blue:0.48 alpha:1] forState:UIControlStateNormal];
    [_loginButton addTarget:self action:@selector(loginBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_loginButton];
    
    
    //鍵盤監聽
    _keyboardIsShow = NO;
    //鍵盤出現或改變時收到訊息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    // 鍵盤退出時收到訊息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    // 輸入框
    _userTextField.delegate = self;
    _passTextField.delegate = self;
    _unitTextField.delegate = self;
    
    _userTextField.placeholder = @"使用者名稱";
    _passTextField.placeholder = @"密碼";
    _unitTextField.placeholder = @"單位識別碼";
    
    _userTextField.textColor = [UIColor whiteColor];
    _passTextField.textColor = [UIColor whiteColor];
    _unitTextField.textColor = [UIColor whiteColor];
    
    _userTextField.textAlignment = NSTextAlignmentCenter;
    _passTextField.textAlignment = NSTextAlignmentCenter;
    _unitTextField.textAlignment = NSTextAlignmentCenter;
    
    //指定編輯時鍵盤的return鍵型別
    _userTextField.returnKeyType = UIReturnKeyNext;
    _passTextField.returnKeyType = UIReturnKeyNext;
    _unitTextField.returnKeyType = UIReturnKeyDone;
    
    //註冊鍵盤響應事件方法
    [_userTextField addTarget:self action:@selector(nextOnKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];
    [_passTextField addTarget:self action:@selector(nextOnKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];
    [_unitTextField addTarget:self action:@selector(nextOnKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];

    //新增手勢,點選螢幕其他區域關閉鍵盤的操作
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidenKeyboard)];
    gesture.numberOfTapsRequired = 1;
    [self.view addGestureRecognizer:gesture];
    

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *userNameStr = [defaults objectForKey:@"UserName"];
    NSString *passwordStr = [defaults objectForKey:@"Password"];
    if ([defaults objectForKey:@"ComCode"]) {
        
        NSString *comCode = [NSString stringWithFormat:@"%@", [defaults objectForKey:@"ComCode"]];
        _unitTextField.text = comCode;
    }

    _passTextField.text = passwordStr;
    _userTextField.text = userNameStr;
    
}
#pragma mark - keyboard
//當鍵盤出現或改變時呼叫
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //獲取鍵盤的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    _keyboardHeight = keyboardRect.size.height;
    _keyboardIsShow = YES;
    NSLog(@"keyboardHeight --- >%ld", _keyboardHeight);
}

- (void)keyboardWillHide:(NSNotification *)aNotification
{
    _keyboardIsShow = NO;
}
#pragma mark - textField
-(void) resumeView
{
    NSTimeInterval animationDuration = 0.3f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    
    CGRect rect=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    self.view.frame=rect;
    [UIView commitAnimations];
}
//點選鍵盤上的Return按鈕響應的方法
-(void)nextOnKeyboard:(UITextField *)sender
{
    if (sender == _userTextField) {
        [_passTextField becomeFirstResponder];
    }else if (sender == _passTextField){
        [_unitTextField becomeFirstResponder];
    }else {
        [self hidenKeyboard];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_userTextField resignFirstResponder];
    [_passTextField resignFirstResponder];
    [_unitTextField resignFirstResponder];
}
//隱藏鍵盤的方法
-(void)hidenKeyboard
{
    [self.passTextField resignFirstResponder];
    [self.unitTextField resignFirstResponder];
    [self.userTextField resignFirstResponder];
    [self resumeView];
}
#pragma mark - protocol
//textFieldProtocol
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    if (textField == _userTextField) {
        _userInputBackImageView.hidden = NO;
    }else if (textField == _passTextField){
        _passwordInputBackImageView.hidden = NO;
    }else if (textField == _unitTextField){
        _unitInputBackImageView.hidden = NO;
    }
    
    
    NSTimeInterval animationDuration = 0.3f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    float width = self.view.frame.size.width;
    float height = self.view.frame.size.height;
    CGRect textFieldFrame = [textField convertRect:textField.frame toView:self.view];
    // 上移
    if (_keyboardIsShow) {
        float y = self.view.frame.origin.y;
        if (height - textFieldFrame.origin.y - y - _keyboardHeight > 90) {
            return YES;
        }
        CGRect rect = CGRectMake(0.0f, y - textField.frame.size.height, width, height);
        self.view.frame = rect;
    } else {
        
        int offset = textFieldFrame.origin.y + 90 - (height - 270);
        NSLog(@"offset --- >%d",offset);
        CGRect rect = CGRectMake(0.0f, - offset, width, height);
        self.view.frame = rect;
    }
    [UIView commitAnimations];
    
    return YES;
    
}
#pragma mark 登入方法
- (void)loginBtnAction:(id)sender{
    [self hidenKeyboard];
 
    
    _progressView = [MRProgressOverlayView new];
    _progressView.titleLabelText = @"登入中,請稍後...";
    [self.view addSubview:_progressView];
    [_progressView show:YES];

    NSString *userNameStr = _userTextField.text;
    NSString *passwordStr = _passTextField.text;
    int comCode = [_unitTextField.text intValue];
    
    LoginReq *loginreq = [[[[[LoginReq builder] setComCode:comCode] setUserName:userNameStr] setPassword:passwordStr] build];
    
    [PBHttpMethod postDataByString:[URLPATH stringByAppendingString:@"AppUri"] BODYData:[loginreq data] WithDataBlock:^(id data) {
    
        ARes *ares = nil;
        if (data != nil) {
            ares = [ARes parseFromData:data];
        }
        if (ares.err) {
            //NSLog(@" ares.err ->%d", ares.err);
            // else 請求中發生錯誤!
            dispatch_async(dispatch_get_main_queue(), ^{
                [_progressView dismiss:YES];
                GetXMLData *getXMlData = [[GetXMLData alloc] init];
                [getXMlData startParser];
                for (ErrorCode *err in getXMlData.dataArray) {
                    if (ares.err == err.ErrCode) {
                        [self showLoginViewAlertWithMessage:[NSString stringWithFormat:@"%@", err.ErrMsg]];
                        break;
                    }
                }
            });
            
        }else{
            NSLog(@"app的子伺服器網址%@", ares.msg);
            [PBHttpMethod postDataByString:[ares.msg stringByAppendingString:@"Login"] BODYData:[loginreq data] WithDataBlock:^(id data){
                LoginRes *loginRes = nil;
                if (data != nil) {
                    loginRes = [LoginRes parseFromData:data];
                }
                if (loginRes.aRes.err == 0) {
                    
                    //設定標籤
                    
                    UToken *utoken = [[[[[UToken builder] setToken:loginRes.uToken.token] setUid:loginRes.uToken.uid] setMethodName:@"MemberTagList"] build];
                    NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
                    [rawOutput open];
                    [utoken writeDelimitedToOutputStream:rawOutput];
                    NSData * data = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
                    
                    [PBHttpMethod postDataByString:[ares.msg stringByAppendingString:@"PushMessage"] BODYData:data WithDataBlock:^(id data) {
                        
                        
                        MemberTag *tag = [MemberTag parseFromData:data];
                        NSMutableSet *tags = [NSMutableSet setWithArray:tag.tag];
                        
                        
                        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                        [defaults setObject:ares.msg forKey:@"subURL"];
                        [defaults setObject:userNameStr forKey:@"UserName"];
                        [defaults setObject:passwordStr forKey:@"Password"];
                        [defaults setObject:[NSNumber numberWithInt:comCode] forKey:@"ComCode"];
                        [defaults setObject:[NSNumber numberWithInt:loginRes.aRes.err] forKey:@"err"];
                        [defaults setObject:[NSNumber numberWithInt:loginRes.uToken.uid] forKey:@"uid"];
                        [defaults setObject:[NSNumber numberWithInt:loginRes.deptId] forKey:@"deptId"];
                        [defaults setObject:loginRes.uToken.token forKey:@"token"];
                        
                        if (loginRes.permission != nil) {
                            
                            NSString *perStr = @"";
                            for (NSInteger i = 0; i< loginRes.permission.count; i++) {
                                if (i == 0) {
                                    perStr = [NSString stringWithFormat:@"%@", loginRes.permission[i]];
                                }else{
                                    perStr = [NSString stringWithFormat:@"%@|%@", perStr, loginRes.permission[i]];
                                }
                            }
                            [defaults setObject:perStr forKey:@"permission"];
                            NSLog(@"許可權》》》》》》%@", perStr);
                        }
                        
                        for (FunCom *funcom in loginRes.functions) {
                            _fun = [NSEntityDescription insertNewObjectForEntityForName:@"Fun" inManagedObjectContext:_manager.managedObjectContext];
                            _fun.key = funcom.key;
                            _fun.value = funcom.value;
                            _fun.endTime = funcom.endTime;
                            _fun.name = funcom.name;
                            _fun.summary = funcom.summary;
                            _fun.remark = funcom.remark;
                            _fun.str1 = funcom.str1;
                            _fun.contact = funcom.contact;
                            
                            [_manager saveContext];
                        }
                        for (AppDataVersion *appDataVersion in loginRes.dataVersion) {
                            [defaults setObject:appDataVersion.dataName forKey:@"dataName"];
                            [defaults setObject:[NSNumber numberWithInteger:appDataVersion.version] forKey:@"endTime"];
                        }
                        for (DicSS *diss in loginRes.uConfig) {
                            [defaults setObject:diss.value forKey:diss.key];
                        }
                        [defaults synchronize];
                        [JPUSHService setTags:tags callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];

                    } WithResponseBlock:^(NSURLResponse *response) {
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            [_progressView dismiss:YES];
                            
                            NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
                            NSInteger responseStatusCode = [httpResponse statusCode];
                            if (responseStatusCode != 200){
                                
                                if (responseStatusCode == 0) {
                                    [self showLoginViewAlertWithMessage:@"網路請求失敗,請檢查網路"];
                                }else{
                                    
                                    [self showLoginViewAlertWithMessage:@"伺服器異常,請稍後再試"];
                                }
                            }
                        });
                        
                    } WithErroBlock:^(NSError *error) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            NSLog(@"%@", [ares.msg stringByAppendingString:@"PushMessage"]);
                            [_progressView dismiss:YES];
                            [self showLoginViewAlertWithMessage:@"請求中發生錯誤"];
                        });

                        
                        
                    }];

                }else{
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [_progressView dismiss:YES];
                        GetXMLData *getXMlData = [[GetXMLData alloc] init];
                        [getXMlData startParser];
                        for (ErrorCode *err in getXMlData.dataArray) {
                            if (loginRes.aRes.err == err.ErrCode) {
                                [self showLoginViewAlertWithMessage:[NSString stringWithFormat:@"%@", err.ErrMsg]];
                                break;
                            }
                        }
                    });
                }

            } WithResponseBlock:^(NSURLResponse *response) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [_progressView dismiss:YES];
                    
                    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
                    NSInteger responseStatusCode = [httpResponse statusCode];
                    if (responseStatusCode != 200){
                        
                        if (responseStatusCode == 0) {
                            [self showLoginViewAlertWithMessage:@"網路請求失敗,請檢查網路"];
                        }else{
                            
                            [self showLoginViewAlertWithMessage:@"伺服器異常,請稍後再試"];
                        }
                    }
                });
            } WithErroBlock:^(NSError *error) {
                [_progressView dismiss:YES];
                [self showLoginViewAlertWithMessage:@"請求中發生錯誤!"];

            }];
        }
            
          }WithResponseBlock:^(NSURLResponse *response) {
              
              dispatch_async(dispatch_get_main_queue(), ^{
                  
                  [_progressView dismiss:YES];
                 
                  NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
                  NSInteger responseStatusCode = [httpResponse statusCode];
                  if (responseStatusCode != 200){
                      
                      if (responseStatusCode == 0) {
                          [self showLoginViewAlertWithMessage:@"網路請求失敗,請檢查網路"];
                      }else{
                          
                          [self showLoginViewAlertWithMessage:@"伺服器異常,請稍後再試"];
                      }
                  }
              });
        
    } WithErroBlock:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
     
            [_progressView dismiss:YES];
            [self showLoginViewAlertWithMessage:@"請求中發生錯誤!"];
        });

    }];
}

#pragma mark - 主執行緒更新UI
- (void)updateUI:(NSString *)message{
    [self showLoginViewAlertWithMessage:message];
    [_progressView dismiss:YES];
}

// AlertView
-(void) showLoginViewAlertWithMessage:(NSString *) message
{
//    // 準備初始化配置引數
//    NSString *okButtonTitle = @"確定";
//    // 初始化
//    UIAlertController *alertDialog = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertAction *okAction = [UIAlertAction actionWithTitle:okButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//    }];
//    [alertDialog addAction:okAction];
//    
//    // 呈現警告檢視
//    [self presentViewController:alertDialog animated:YES completion:nil];
    DXAlertView *alert = [[DXAlertView alloc]initWithTitle:@"提示" contentText:message leftButtonTitle:nil rightButtonTitle:@"確定"];
    [alert show];
    alert.leftBlock = ^() {
        NSLog(@"left button clicked");
    };
}
- (void)tagsAliasCallback:(int)iResCode
                     tags:(NSSet *)tags
                    alias:(NSString *)alias {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        NSString *callbackString =
        [NSString stringWithFormat:@"《《《《《《-----%d, \ntags: %@, \nalias: %@\n", iResCode, [self logSet:tags], alias];
        NSLog(@"------- TagsAlias回撥:%@", callbackString);
        [_progressView dismiss:YES];
        if (!iResCode) {
            [self nextMainPage];
        }else{
             [_progressView dismiss:YES];
            //清除userdefault
            NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
            [[NSUserDefaults standardUserDefaults] removePersistentDomainForName: appDomain];
            DXAlertView *alert = [[DXAlertView alloc]initWithTitle:@"提示" contentText:[NSString stringWithFormat:@"獲取推送標籤失敗,請重新登入"] leftButtonTitle:nil rightButtonTitle:@"確定"];
            [alert show];
            alert.leftBlock = ^() {
                NSLog(@"left button clicked");
            };
            
        }
    });
}
- (void)nextMainPage{
//    CATransition *animation = [CATransition animation];
//    animation.duration = 1.0;
//    animation.timingFunction = UIViewAnimationCurveEaseInOut;
//    animation.type = @"pageCurl";
//    animation.type = kCATransitionFade;
//    animation.subtype = kCATransitionFromLeft;
//    [self.view.window.layer addAnimation:animation forKey:nil];
//    [self dismissViewControllerAnimated:YES completion:nil];
    
    
    RootTabBarController *rootVC=[[RootTabBarController alloc]init];
    rootVC.delegate = self;
    DDMenuController *menuController = [[DDMenuController alloc] initWithRootViewController:rootVC];
    PersonInfoLeftViewController *leftController = [[PersonInfoLeftViewController alloc] init];
    menuController.leftViewController = leftController;
    [UIApplication sharedApplication].delegate.window.rootViewController = menuController;
    
}
- (NSString *)logSet:(NSSet *)dic {
    if (![dic count]) {
        return nil;
    }
    NSString *tempStr1 =
    [[dic description] stringByReplacingOccurrencesOfString:@"\\u"
                                                 withString:@"\\U"];
    NSString *tempStr2 =
    [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
    NSString *tempStr3 =
    [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
    NSString *str = [NSPropertyListSerialization propertyListFromData:tempData
                                     mutabilityOption:NSPropertyListImmutable
                                               format:NULL
                                     errorDescription:NULL];
    return str;
}
-(void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

相關文章