// // RegistViewController.m // Ifish // // Created by imac on 15/9/27. // Copyright © 2015年 imac. All rights reserved. // #import "RegistViewController.h" //#import "JPUSHService.h" #import "LogInViewController.h" #import "UserModel.h" #import "AFNetworking.h" #import "MyMD5.h" #import "LeftViewController.h" #import "RightViewController.h" #import "AgreementViewController.h" #import "MyIntroductionViewController.h" #import "ConnectWifiViewController.h" #import "WXApi.h" #import "WXApiManager.h" #import "ChatroomModel.h" //#import //#import //#import //#import //#import //#import "FirstConnectWifiController.h" //#import "SelectDeviceViewController.h" //#import "IfishSelectCardViewController.h" #import "IfishBindDeviceSelectViewController.h" #import "IfishMianTabViewController.h" #import "IfishUserDataUnity.h" #import "IfishNewsModel.h" #import #import #import "XWCountryCodeController.h" #import @interface RegistViewController () { BOOL _showed;//显示过了 // dispatch_source_t _timer1; UIButton *hpBtn; BOOL gouxuan; } @property (weak, nonatomic) IBOutlet UIButton *timeBtn; @property(nonatomic,copy)NSString*verifyData; @property(nonatomic,copy) NSString *areaCode; @property (weak, nonatomic) IBOutlet UIButton *resignBtn; @property (weak, nonatomic) IBOutlet UIButton *registBtn; - (IBAction)agreementBtn:(id)sender; @property(nonatomic,strong)MBProgressHUD *HUD; @property(nonatomic,strong)NSMutableArray*deviceArry; @property(nonatomic,strong)UIActivityIndicatorView*indicatorView; //@property(nonatomic)BMKLocationService*locService; @property (nonatomic,strong ) CLLocationManager *locationManager;//定位服务 @property (nonatomic,copy) NSString *currentCity;//城市 @property(nonatomic) double longitude; @property(nonatomic) double latitude; @property(nonatomic,copy) NSString *adderss; @property (weak, nonatomic) IBOutlet UILabel *qrcodeSwitchLbl; @property (nonatomic,copy) NSDictionary *expara;//城市 @property (weak, nonatomic) IBOutlet UIView *styleView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *wechatConstraints; @end extern BOOL formLogIn; @implementation RegistViewController -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.isBind=NO; self.isFromLogin=NO; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; [MobSDK uploadPrivacyPermissionStatus:YES onResult:^(BOOL success) { }]; _deviceArry=[[NSMutableArray alloc]init]; //默认中国大陆 self.areaCode = @"86"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [self.countrySelectBtn addTarget:self action:@selector(countrySelectBtnAction:) forControlEvents:UIControlEventTouchUpInside]; self.registBtn.backgroundColor=COLOR_LABEL_TITLE; self.view.backgroundColor= [UIColor colorWithPatternImage:[UIImage imageNamed:@"enter_background"]]; if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更 }else{ [self.passwordTextField setValue:[UIColor colorWithRed:153/255.0f green:153/255.0f blue:153/255.0f alpha:1] forKeyPath:@"_placeholderLabel.textColor"]; [self.phoneNumberTextField setValue:[UIColor colorWithRed:153/255.0f green:153/255.0f blue:153/255.0f alpha:1] forKeyPath:@"_placeholderLabel.textColor"]; [self.verifyTextField setValue:[UIColor colorWithRed:153/255.0f green:153/255.0f blue:153/255.0f alpha:1] forKeyPath:@"_placeholderLabel.textColor"]; } [self addNaviItem]; [self setTextkeyboadType]; self.phoneNumberTextField.delegate=self; self.verifyTextField.delegate=self; self.passwordTextField.delegate=self; self.navigationItem.hidesBackButton=YES; [self getLocation]; if ([WXApi isWXAppInstalled]&&!self.isBind) { self.styleView.hidden=NO; if ([CommonUtils isIphoneX]) { //self.wechatConstraints.constant=-30; } } } #pragma mark 定位 -(void)getLocation{ //初始化BMKLocationService // _locService=[[BMKLocationService alloc]init]; // _locService.delegate=self; // //启动LocationService // [_locService startUserLocationService]; // _geocodesearch=[[BMKGeoCodeSearch alloc]init]; if ([CLLocationManager locationServicesEnabled]) { _locationManager = [[CLLocationManager alloc]init]; _locationManager.delegate = self; [_locationManager requestAlwaysAuthorization]; _currentCity = [[NSString alloc]init]; [_locationManager requestWhenInUseAuthorization]; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.distanceFilter = 5.0; [_locationManager startUpdatingLocation]; } } #pragma mark - 定位失败 -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置中打开定位" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"打开定位" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if([[UIApplication sharedApplication] canOpenURL:url]) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; }else { [[UIApplication sharedApplication] openURL:url]; } } }]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:cancel]; [alert addAction:ok]; // [self presentViewController:alert animated:YES completion:nil]; } #pragma mark - 定位成功 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ [_locationManager stopUpdatingLocation]; CLLocation *currentLocation = [locations lastObject]; CLGeocoder *geoCoder = [[CLGeocoder alloc]init]; //当前的经纬度 NSLog(@"当前的经纬度 %f,%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude); self.latitude=currentLocation.coordinate.latitude; self.longitude=currentLocation.coordinate.longitude; //这里的代码是为了判断didUpdateLocations调用了几次 有可能会出现多次调用 为了避免不必要的麻烦 在这里加个if判断 如果大于1.0就return NSTimeInterval locationAge = -[currentLocation.timestamp timeIntervalSinceNow]; if (locationAge > 1.0){//如果调用已经一次,不再执行 return; } //地理反编码 可以根据坐标(经纬度)确定位置信息(街道 门牌等) [geoCoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) { if (placemarks.count >0) { CLPlacemark *placeMark = placemarks[0]; _currentCity = placeMark.locality; if (!_currentCity) { _currentCity = @"无法定位当前城市"; } //看需求定义一个全局变量来接收赋值 NSLog(@"当前国家 - %@",placeMark.country);//当前国家 NSLog(@"当前城市 - %@",_currentCity);//当前城市 NSLog(@"当前位置 - %@",placeMark.subLocality);//当前位置 NSLog(@"当前街道 - %@",placeMark.thoroughfare);//当前街道 NSLog(@"具体地址 - %@",placeMark.name);//具体地址 NSString *message = [NSString stringWithFormat:@"%@,%@,%@,%@,%@",placeMark.country,_currentCity,placeMark.subLocality,placeMark.thoroughfare,placeMark.name]; NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; NSString*address=message; self.adderss = address; [userdefult setObject:address forKey:@"address"]; [userdefult setDouble:self.latitude forKey:@"userlatitude"]; [userdefult setDouble:self.longitude forKey:@"userlongitude"]; [userdefult synchronize]; }else if (error == nil && placemarks.count){ NSLog(@"NO location and error return"); }else if (error){ NSLog(@"loction error:%@",error); } }]; } #pragma mark-- 获取验证(阿里)使用中 -(void)timeFire{ [IFISHHTTPTOOL getVerifyCodeWithTimerButton:_timeBtn addPhoneNumber:self.phoneNumberTextField.text addSendType:@"1" backData:^(NSString *verifycode) { _verifyData=verifycode; NSLog(@"%@",_verifyData); }]; } #pragma mark - 获取验证码(SMS) -(void)getVerifycode{ BOOL isTextCode = [[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"短信验证码"]; [IFISHHTTPTOOL getverifyWithTimerButton:_timeBtn addphoneNumber:self.phoneNumberTextField.text zone:self.areaCode isTextCode:isTextCode result:^(NSError *err) { }]; } - (IBAction)qrcodeSwithBtnClicked:(UIButton *)sender { // if ([[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"语音验证码"]) { // [self.timeBtn setTitle:@"短信验证码" forState:UIControlStateNormal]; // self.qrcodeSwitchLbl.text = @"语音验证码"; // } else if ([[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"短信验证码"]) { // [self.timeBtn setTitle:@"语音验证码" forState:UIControlStateNormal]; // self.qrcodeSwitchLbl.text = @"短信验证码"; // } } #pragma mark-设置键盘样式 -(void)setTextkeyboadType{ // self.phoneNumberTextField.keyboardType=UIKeyboardTypeNumberPad; self.passwordTextField.secureTextEntry=YES; self.phoneNumberTextField.layer.masksToBounds=YES; CGRect verifyTextFieldRect= CGRectMake(self.verifyTextField.bounds.origin.x,self.verifyTextField.bounds.origin.x,kScreenSize.width-31*2 -80,self.verifyTextField.bounds.size.height); UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:verifyTextFieldRect byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer =[[CAShapeLayer alloc] init]; maskLayer.frame = verifyTextFieldRect; maskLayer.path = maskPath.CGPath; //self.verifyTextField.layer.mask = maskLayer; self.verifyTextField.layer.masksToBounds=YES; self.verifyTextField.layer.cornerRadius=8; // CGRect timeBtnRect= CGRectMake(_timeBtn.bounds.origin.x,_timeBtn.bounds.origin.x,_timeBtn.bounds.size.width,_timeBtn.bounds.size.height); // UIBezierPath *maskPathtimeBtn=[UIBezierPath bezierPathWithRoundedRect:timeBtnRect byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)]; // CAShapeLayer *maskLayertimeBtn =[[CAShapeLayer alloc] init]; // maskLayertimeBtn.frame = timeBtnRect; // maskLayertimeBtn.path = maskPathtimeBtn.CGPath; //_timeBtn.layer.mask = maskLayertimeBtn; self.phoneNumberTextField.layer.cornerRadius=8; self.passwordTextField.layer.masksToBounds=YES; self.passwordTextField.layer.cornerRadius=8; //_timeBtn.backgroundColor=COLOR_LABEL_TITLE; //[_timeBtn setImage:[UIImage imageNamed:@"registered_icon_validation"] forState:UIControlStateNormal]; [_timeBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_validation"] forState:UIControlStateNormal]; _registBtn.backgroundColor=COLOR_LABEL_TITLE; _registBtn.layer.masksToBounds=YES; _registBtn.layer.cornerRadius=8; UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)]; self.phoneNumberTextField.leftView=phoneView; self.phoneNumberTextField.leftViewMode=UITextFieldViewModeAlways; UIView*phoneView1=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)]; self.verifyTextField.leftView=phoneView1; UIView*phoneView2=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)]; self.verifyTextField.leftViewMode=UITextFieldViewModeAlways; self.passwordTextField.leftView=phoneView2; self.passwordTextField.leftViewMode=UITextFieldViewModeAlways; // [_searchBar setSearchTextPositionAdjustment:UIOffsetMake(10, 0)]; self.countryView.layer.masksToBounds = YES; self.countryView.layer.cornerRadius = 8; } #pragma mark-设置导航按钮 -(void)addNaviItem{ UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-200)/2.0, 0, 200, 44)]; labe.text=@"注册"; labe.textAlignment=NSTextAlignmentCenter; labe.textColor=[UIColor whiteColor]; self.navigationItem.titleView=labe; BOOL skiped=NO; NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; UserModel*model=[dataContorl getUserInfo]; if (model.unionId) { skiped =[userDefsult boolForKey:model.unionId]; } UIButton*rightButton = [[UIButton alloc]initWithFrame:CGRectMake(25,0,60,60)]; [rightButton setTitle:@"登录" forState:UIControlStateNormal]; rightButton.backgroundColor=[UIColor clearColor]; [rightButton.titleLabel setFont:[UIFont systemFontOfSize:14]]; [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(rightButtonClick:) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithCustomView:rightButton]; // rightItem.tintColor=[UIColor whiteColor]; // [rightItem setTintColor:[UIColor whiteColor]]; if (self.isBind) { labe.text=@"绑定手机"; [self.resignBtn setTitle:@"确定" forState:UIControlStateNormal]; if (!skiped&&self.isFromLogin) { [rightButton setTitle:@"跳过" forState:UIControlStateNormal]; self.navigationItem.rightBarButtonItem= rightItem; } else { UIButton* _bakbutton = [UIButton buttonWithType:UIButtonTypeCustom]; _bakbutton.frame = CGRectMake(0,0,48,44); [_bakbutton setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; _bakbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside]; // [_bakbutton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)]; UIBarButtonItem*_back =[[UIBarButtonItem alloc] initWithCustomView:_bakbutton]; UIBarButtonItem *fixedButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; fixedButtonItem.width = -kSizeFrom750(30); self.navigationItem.leftBarButtonItems = @[fixedButtonItem, _back]; } } else { self.navigationItem.rightBarButtonItem= rightItem; } [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; // [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal]; } -(void)rightButtonClick:(UIButton *)sender{ if (self.isBind) { NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; UserModel*model=[dataContorl getUserInfo]; if (model.unionId) { [userDefsult setBool:YES forKey:model.unionId]; [userDefsult synchronize]; [[IfishUserDataUnity shareDataInstance] setAppTabRoot]; } } else { LogInViewController *login=[[LogInViewController alloc]init]; [self.navigationController pushViewController:login animated:YES]; } } -(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } //-(BOOL)isExistUserName:(NSString *)name{ // // //DataCenter 去本地 检测 有没有存储 // UserModel *model=[[DataCenter defaultDtacenter]valueForKey:name]; // if (model) { // return YES;//存在 // // }else{ // return NO; // } //} #pragma mark-处理收键盘 -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; // [self resumeView]; return YES; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self hiddenKeybord]; //[self resumeView]; } -(void)hiddenKeybord{ [self.phoneNumberTextField resignFirstResponder]; [self.passwordTextField resignFirstResponder]; [self.verifyTextField resignFirstResponder]; } #pragma mark-点击注册 - (IBAction)registBtn:(id)sender { UIButton *btn = (UIButton *)sender; if (self.verifyTextField.text.length==0) { [self.view makeToast:@"请输入验证码"]; return; } if (self.phoneNumberTextField.text.length==0||self.passwordTextField.text.length==0) { [self.view makeToast:@"用户名或者密码不能为空"]; return; } //self.verifyTextField.text=_verifyData; if (self.passwordTextField.text.length<6) { [self.view makeToast:@"请输入最小六位密码"]; return; } btn.userInteractionEnabled=NO; btn.backgroundColor=[UIColor lightGrayColor]; if ([self.verifyTextField.text isEqualToString:_verifyData]) { if (self.isBind) { [self bindPhone]; } else { [self ifishAddUser]; } } else { NSString *str =@"验证码验证失败"; [self.view makeToast:str]; btn.userInteractionEnabled=YES; btn.backgroundColor=COLOR_LABEL_TITLE; } // [SMSSDK commitVerificationCode:self.verifyTextField.text phoneNumber:self.phoneNumberTextField.text zone:self.areaCode result:^(NSError *error) { // // { // if (!error) // { // // NSLog(@"验证成功"); // if (self.isBind) // { // [self bindPhone]; // } // else // { // [self ifishAddUser]; // } // // // } // else // { // NSLog(@"错误信息:%@",error); // NSString *str =@"验证码验证失败"; // [self.view makeToast:str]; // btn.userInteractionEnabled=YES; // btn.backgroundColor=COLOR_LABEL_TITLE; // // } // } // }]; } #pragma mark - 注册 -(void)ifishAddUser{ NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; NSString*address=[userDefsult objectForKey:@"address"]; NSString*passStr=[MyMD5 md5:self.passwordTextField.text]; if (!address) { NSLog(@"addressnil"); address = @"暂时未获取到地址信息"; } if (!self.latitude) { self.latitude = 0; } if (!self.longitude) { self.longitude =0; } __weak typeof (self) weakSelf = self; [AFHttpTool addUserWithPhoneNumber:weakSelf.phoneNumberTextField.text password:passStr phoneType:@"ios" address:address longitude:weakSelf.longitude latitude:weakSelf.latitude success:^(id response) { if (response) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSLog(@"resultDic:%@",resultDic); if ([resultDic[@"result"] isEqualToString:@"100"]) { NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; NSString*userName=weakSelf.phoneNumberTextField.text; NSString*password=weakSelf.passwordTextField.text; [userdefult setObject:password forKey:@"password"]; [userdefult setObject:userName forKey:@"name"]; //是否退出登陆 [userdefult setObject:@"0" forKey:@"isExit"]; [userdefult synchronize]; [weakSelf logIn]; }else if ([resultDic[@"result"] isEqualToString:@"201"]){ [weakSelf.view makeToast:@"手机号已经注册过"]; }else{ [weakSelf.view makeToast:@"注册失败"]; } } } failure:^(NSError *err) { _registBtn.userInteractionEnabled=YES; _registBtn.backgroundColor=COLOR_LABEL_TITLE; UIAlertView *alter =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请检查您的网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alter show]; NSString *erstr =[NSString stringWithFormat:@"%@",err]; BLYLog(BuglyLogLevelError, erstr); }]; } -(void)bindPhone { UserModel*user=[dataContorl getUserInfo]; if (user.unionId) { NSMutableDictionary*para=[[NSMutableDictionary alloc]initWithDictionary:@{@"unionId":user.unionId,@"phoneNum":self.phoneNumberTextField.text}]; if (self.passwordTextField.text.length) { para[@"password"]=[MyMD5 md5:self.passwordTextField.text]; } [AFHttpTool requestWihtMethod:RequestMethodTypePost url:kUserBindPhone params:para success:^(id response) { if (response) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSLog(@"resultDic:%@",resultDic); [[NSNotificationCenter defaultCenter] postNotificationName:@"updateUserInfobyValidation" object:nil]; if ([resultDic[@"result"] isEqualToString:@"100"]) { NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; NSString*userName=self.phoneNumberTextField.text; NSString*password=self.passwordTextField.text; [userdefult setObject:password forKey:@"password"]; [userdefult setObject:userName forKey:@"name"]; //是否退出登陆 [userdefult setObject:@"0" forKey:@"isExit"]; [userdefult synchronize]; user.phoneNumber=self.phoneNumberTextField.text; [[DataCenter defaultDtacenter]setValue:user forKey:@"UserLogIn"]; [self.view makeToast:@"绑定成功"]; if (self.isFromLogin) { [[IfishUserDataUnity shareDataInstance] setAppTabRoot]; } else { [self.navigationController popViewControllerAnimated:YES]; } }else if ([resultDic[@"result"] isEqualToString:@"204"]){ [self.view makeToast:@"验证码错误"]; }else{ [self.view makeToast:@"修改失败"]; } } } failure:^(NSError *err) { }]; } } -(void)goBackAction{ [self.navigationController popViewControllerAnimated:YES]; } #pragma mark- 极光别名注册 - (void)tagsAliasCallback:(int)iResCode tags:(NSSet*)tags alias:(NSString*)alias { NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias); } #pragma mark-爱鱼奇协议按钮 - (IBAction)chooseBtn:(id)sender { UIButton*xuanBtn=(UIButton*)sender; if (gouxuan) { [xuanBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_tick_uncheck"] forState:UIControlStateNormal]; _registBtn.userInteractionEnabled=YES; _registBtn.backgroundColor=COLOR_LABEL_TITLE; gouxuan=NO; [MobSDK uploadPrivacyPermissionStatus:NO onResult:^(BOOL success) { }]; }else{ [xuanBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_tick_selected"] forState:UIControlStateNormal]; _registBtn.userInteractionEnabled=NO; _registBtn.backgroundColor=[UIColor lightGrayColor]; gouxuan=YES; [MobSDK uploadPrivacyPermissionStatus:YES onResult:^(BOOL success) { }]; } } // /////键盘消失事件 - (void) keyboardWillHide:(NSNotification *)notify { // 键盘动画时间 double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //视图下沉恢复原状 [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0, NavigationBarHeight, self.view.frame.size.width, self.view.frame.size.height); }]; } -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { // 适应第三方键盘 if (textField==self.phoneNumberTextField) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradWillShow1:) name:UIKeyboardWillShowNotification object:nil]; }else if (textField==self.verifyTextField){ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradWillShow2:) name:UIKeyboardWillShowNotification object:nil]; }else if (textField==self.passwordTextField){ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradWillShow3:) name:UIKeyboardWillShowNotification object:nil]; } return YES; } //恢复原始视图位置 //-(void)resumeView //{ // // NSTimeInterval animationDuration=0.30f; // [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; // [UIView setAnimationDuration:animationDuration]; // float width = self.view.frame.size.width; // float height = self.view.frame.size.height; // //如果当前View是父视图,则Y为20个像素高度,如果当前View为其他View的子视图,则动态调节Y的高度 // float Y = 0.0f; // CGRect rect=CGRectMake(0.0f,Y,width,height); // self.view.frame=rect; // [UIView commitAnimations]; // //} - (void) keyboradWillShow1:(NSNotification *)notification { //获取键盘高度,在不同设备上,以及中英文下是不同的 CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD) CGFloat offset = (_phoneNumberTextField.frame.origin.y+_phoneNumberTextField.frame.size.height+INTERVAL_KEYBOARD) - (self.view.frame.size.height - kbHeight); // 取得键盘的动画时间,这样可以在视图上移的时候更连贯 double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //将视图上移计算好的偏移 if(offset > 0) { [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height); }]; } } - (void) keyboradWillShow2:(NSNotification *)notification { //获取键盘高度,在不同设备上,以及中英文下是不同的 CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD) CGFloat offset = (_verifyTextField.frame.origin.y+_verifyTextField.frame.size.height+INTERVAL_KEYBOARD) - (self.view.frame.size.height - kbHeight); // 取得键盘的动画时间,这样可以在视图上移的时候更连贯 double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //将视图上移计算好的偏移 if(offset > 0) { [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height); }]; } } - (void) keyboradWillShow3:(NSNotification *)notification { //获取键盘高度,在不同设备上,以及中英文下是不同的 CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD) CGFloat offset = (_passwordTextField.frame.origin.y+_passwordTextField.frame.size.height+INTERVAL_KEYBOARD) - (self.view.frame.size.height - kbHeight); // 取得键盘的动画时间,这样可以在视图上移的时候更连贯 double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //将视图上移计算好的偏移 if(offset > 0) { [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height); }]; } } //爱鱼奇协议 - (IBAction)agreementBtn:(id)sender { AgreementViewController*agreement=[[AgreementViewController alloc]init]; [self.navigationController pushViewController:agreement animated:YES]; } - (IBAction)verifyBtn:(id)sender { //阿里验证码 [self timeFire]; // [self getVerifycode]; } -(void)showTitle:(NSString*)title messsage:(NSString*)message{ UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; NSTimeInterval dismissSeconds=1.0; [alert show]; [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds]; } -(void)dismissAlert:(UIAlertView*)alertView{ [alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES]; } #pragma mark 引导页 -(void)viewWillAppear:(BOOL)animated{ // _geocodesearch.delegate=self;// 此处记得不用的时候需要置nil,否则影响内存的释放 // _locService.delegate=self; static dispatch_once_t disOnce; dispatch_once(&disOnce, ^ { if (_showed) { return; } NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults]; if ([accountDefaults boolForKey:@"showed"]==YES) { return; }else{ [self showIntroduce]; } }); } -(void)viewWillDisappear:(BOOL)animated{ // _geocodesearch.delegate=nil; // _locService.delegate=nil; } -(void)showIntroduce{ MyIntroductionViewController*introductionVC=[[MyIntroductionViewController alloc]init]; NSMutableArray * imageNames = [NSMutableArray array]; for (int i=1; i<=3; i++) { if (is_iPhone_X) { [imageNames addObject:[NSString stringWithFormat:@"introlImage_iphonex_%d.jpg",i]]; } else { [imageNames addObject:[NSString stringWithFormat:@"introlImage_%d.png",i]]; } } introductionVC.imageNames=imageNames; introductionVC.hiddenPageControl=NO; introductionVC.introductionStyle=LXIntroductionStyleFullScreenGoButton; introductionVC.goActionCallBack=^(MyIntroductionViewController* intrVC){ [intrVC dismissViewControllerAnimated:YES completion:nil]; _showed=YES; NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; [userdefult setBool:YES forKey:@"showed"]; }; [self presentViewController:introductionVC animated:YES completion:nil]; } #pragma mark 注册成功自动登录 -(void)logIn{ NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; NSString*name=[userDefsult objectForKey:@"name"]; NSString*password=[userDefsult objectForKey:@"password"]; NSString*tokenStr=@""; if (password.length) { tokenStr=[MyMD5 md5:password]; } [AFHttpTool userLogInWithPhoneNumber:name password:tokenStr phoneType:@"ios" address:self.adderss longitude:self.longitude latitude:self.latitude success:^(id response) { NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result=dict[@"result"]; _registBtn.userInteractionEnabled=YES; _registBtn.backgroundColor=COLOR_LABEL_TITLE; if ([result isEqualToString:@"100"]) { NSDictionary*DataDic=dict[@"data"]; [[IfishUserDataUnity shareDataInstance] userAutologinSuccsess:DataDic]; }else if ([result isEqualToString:@"101"]){ [self showTitle:@"" messsage:@"登录失败"]; //登录失败 }else if ([result isEqualToString:@"204"]){ // 验证失败,密码不正确 [self showTitle:@"" messsage:@"验证失败,密码不正确"]; }else if ([result isEqualToString:@"202"]){ // 用户不存在 [self showTitle:@"" messsage:@"用户不存在"]; }else if ([result isEqualToString:@"400"]){ // [self showTitle:@"" messsage:@"安全验证失败"]; } [_indicatorView stopAnimating]; } failure:^(NSError *err) { _registBtn.userInteractionEnabled=YES; _registBtn.backgroundColor=COLOR_LABEL_TITLE; [_indicatorView stopAnimating]; UIAlertView *alter =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"登录异常" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil]; [alter show]; NSLog(@"失败"); NSString *erstr =[NSString stringWithFormat:@"%@",err]; BLYLog(BuglyLogLevelError, erstr); } expara:self.expara]; } - (IBAction)wechatAuthority:(id)sender { AppDelegate*del=(AppDelegate*)[UIApplication sharedApplication].delegate; del.isWechatLogin=YES; [WXApiManager sharedManager].delegate=self; SendAuthReq* req =[[SendAuthReq alloc]init]; req.scope = @"snsapi_userinfo"; req.state = @"ifish7"; [WXApi sendReq:req]; } #pragma mark - WXApiManagerDelegate - (void)managerDidRecvAuthResponse:(SendAuthResp *)response { if (response.errCode==0) { self.expara=@{@"code":response.code}; [self logIn]; } AppDelegate*del=(AppDelegate*)[UIApplication sharedApplication].delegate; del.isWechatLogin=NO; } -(void)creatMyindicaterView{ _indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; _indicatorView.frame=CGRectMake(kScreenSize.width/2-20,kScreenSize.height/2-20,40, 40); [self.view addSubview:_indicatorView]; } //实现相关delegate 处理位置信息更新 //处理方向变更信息 //- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation //{ // //NSLog(@"heading is %@",userLocation.heading); //} //处理位置坐标更新 //- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation //{ // NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); // self.latitude = userLocation.location.coordinate.latitude; // self.longitude = userLocation.location.coordinate.longitude; // static dispatch_once_t disOnce; // dispatch_once(&disOnce, ^ { // // [self reverseGeoCodeWithlatitude:userLocation.location.coordinate.latitude addlongitude:userLocation.location.coordinate.longitude]; // }); // //} /** * 地理反编码 */ //-(void)reverseGeoCodeWithlatitude:(CLLocationDegrees)latitude addlongitude:(CLLocationDegrees)longitude{ // CLLocationCoordinate2D pt=(CLLocationCoordinate2D){latitude,longitude}; // BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init]; // reverseGeocodeSearchOption.reverseGeoPoint=pt; // BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption]; // if(flag) // { // NSLog(@"反geo检索发送成功"); // } // else // { // NSLog(@"反geo检索发送失败"); // } // //} //-(void)dealloc{ // // if (_geocodesearch!=nil) { // _geocodesearch=nil; // } //} #pragma mark BMKGeoCodeSearchDelegate //-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{ // NSLog(@"address%@",result.address); // NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; // NSString*address=result.address; // self.adderss = address; // [userdefult setObject:address forKey:@"address"]; // [userdefult setDouble:self.latitude forKey:@"userlatitude"]; // [userdefult setDouble:self.longitude forKey:@"userlongitude"]; // [userdefult synchronize]; // _geocodesearch.delegate=nil; //} #pragma mark - countrySelectBtnAction -(void)countrySelectBtnAction:(UIButton *)btn{ XWCountryCodeController *CountryCodeVC = [[XWCountryCodeController alloc] init]; //CountryCodeVC.deleagete = self; [CountryCodeVC toReturnCountryCode:^(NSString *countryCodeStr) { [self.countrySelectBtn setTitle:countryCodeStr forState:UIControlStateNormal]; NSArray *array = [countryCodeStr componentsSeparatedByString:@"+"]; self.areaCode = array[1]; }]; [self presentViewController:CountryCodeVC animated:YES completion:nil]; } @end