// // 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 "CenterViewController.h" #import "RightViewController.h" #import "AgreementViewController.h" #import "MyIntroductionViewController.h" #import "ConnectWifiViewController.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" @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 *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) double longitude; @property(nonatomic) double latitude; @property(nonatomic,copy) NSString *adderss; @property (weak, nonatomic) IBOutlet UILabel *qrcodeSwitchLbl; @end extern BOOL formLogIn; @implementation RegistViewController -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; _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"]]; [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]; } #pragma mark 定位 -(void)getLocation{ //初始化BMKLocationService _locService=[[BMKLocationService alloc]init]; _locService.delegate=self; //启动LocationService [_locService startUserLocationService]; _geocodesearch=[[BMKGeoCodeSearch alloc]init]; } #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 isMacth=[dataContorl valiMobile:self.phoneNumberTextField.text]; //if (!isMacth) { // [self.view makeToast:@"请输入正确手机号"]; // return; //} //NSString *zone = [dataContorl areaCode:self.phoneNumberTextField.text]; //self.areaCode = zone; 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(0, 0, 60, 44)]; labe.text=@"注册"; labe.textAlignment=NSTextAlignmentCenter; labe.textColor=[UIColor whiteColor]; self.navigationItem.titleView=labe; // UIButton*rightButton = [[UIButton alloc]initWithFrame:CGRectMake(25,0,60,60)]; // [rightButton setTitle:@"登录" forState:UIControlStateNormal]; // rightButton.backgroundColor=[UIColor clearColor]; // [rightButton addTarget:self action:@selector(rightItemBtn:) forControlEvents:UIControlEventTouchUpInside]; // UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(25,0,60,60)]; // // [imageView addSubview:rightButton]; // imageView.userInteractionEnabled=YES; // UIBarButtonItem*rightItem = [[UIBarButtonItem alloc]initWithCustomView:imageView]; // self.navigationItem.rightBarButtonItem= rightItem; UIBarButtonItem*rightItem= [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStyleDone target:self action:@selector(rightItemBtn:)]; // rightItem.tintColor=[UIColor whiteColor]; // [rightItem setTintColor:[UIColor whiteColor]]; self.navigationItem.rightBarButtonItem= rightItem; [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal]; } -(void)rightItemBtn:(id)sender{ 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]; [SMSSDK commitVerificationCode:self.verifyTextField.text phoneNumber:self.phoneNumberTextField.text zone:self.areaCode result:^(SMSSDKUserInfo *userInfo, NSError *error) { { if (!error) { NSLog(@"验证成功"); [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); }]; } #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; }else{ [xuanBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_tick_selected"] forState:UIControlStateNormal]; _registBtn.userInteractionEnabled=NO; _registBtn.backgroundColor=[UIColor lightGrayColor]; gouxuan=YES; } } // /////键盘消失事件 - (void) keyboardWillHide:(NSNotification *)notify { // 键盘动画时间 double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //视图下沉恢复原状 [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0, 0, 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++) { [imageNames addObject:[NSString stringWithFormat:@"introlImage_%d",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=[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); }]; } -(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