IOS 使用shareSDK发送验证码
来源:互联网 发布:土木工程软件 编辑:程序博客网 时间:2024/06/02 03:40
//// LoginMobileController.m// kykx// 手机发送验证码// Created by zhangyg on 15/7/9.// Copyright (c) 2015年 ytint. All rights reserved.//#import "LoginMobileController.h"#import <SMS_SDK/SMS_SDK.h>#import <SMS_SDK/CountryAndAreaCode.h>#import "CommenData.h"#import "DocPackage.h"#import "AFHTTPRequestOperation.h"@interface LoginMobileController (){ NSTimer* _timer1; NSTimer* _timer2; NSTimer* _timer3;}@endstatic int count = 0;@implementation LoginMobileController-(void)viewDidLoad{ [super viewDidLoad]; //将返回按钮的文字设置不在界面显示 [[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; self.mobile.delegate=self; self.icode.delegate=self; NSLog(@"%@",self.showWho); if([self.showWho isEqualToString:@"1"]){ //修改密码 }else{ //注册 self.navigationItem.title=@"注册"; } //发送验证码 UITapGestureRecognizer *sendcodeGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sendCodeAction)]; self.sendCode.userInteractionEnabled=YES; [self.sendCode addGestureRecognizer:sendcodeGesture]; //下一步 UITapGestureRecognizer *nextGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nextAction)]; self.nextPass.userInteractionEnabled=YES; [self.nextPass addGestureRecognizer:nextGesture];}-(NSInteger)mobileIsRepeat{ //注册手机号是否重复 NSString *stringurl = [NSString stringWithFormat:@"%@cdpt/api/user_is_exist?access_token=0&user_name=%@", BaseURLString,self.mobile.text]; NSURL *url = [NSURL URLWithString:stringurl]; NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:2]; NSError *error; NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]; if (error) { NSLog(@"error=%@",error); [CommenData showNetError:self.navigationController.view]; }else{ NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; NSLog(@"%@",dict); NSNumber *code=[dict code]; if ([code intValue]==200) { if ([[dict infoString] intValue]==0) { //手机号码没有注册 return 1; }else{ //手机号码已经注册 return 0; } }else{ [CommenData showMsgError:self.navigationController.view showMsg:[dict msg]]; } } return -1;}-(void)sendCodeAction{ NSString *regex = @"1[0-9]{10}"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; BOOL isMatch = [pred evaluateWithObject:self.mobile.text]; if (!isMatch){ //手机号码不正确 [CommenData showMsgError:self.navigationController.view showMsg:@"手机号码不正确"]; return; } if([self.showWho isEqualToString:@"1"]){ //修改密码 if ([self mobileIsRepeat]!=0) { if([self mobileIsRepeat]==1){ [CommenData showMsgError:self.navigationController.view showMsg:@"该手机号码没有注册"]; } return; } }else{ //注册 if ([self mobileIsRepeat]!=1) { if([self mobileIsRepeat]==0){ [CommenData showMsgError:self.navigationController.view showMsg:@"该手机号码已经注册"]; } return; } } [SMS_SDK getVerificationCodeBySMSWithPhone:self.mobile.text zone:@"86" result:^(SMS_SDKError *error) { if (!error) { //更新时间 [_timer2 invalidate]; count = 0; NSTimer* timer2=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTime) userInfo:nil repeats:YES]; _timer2=timer2; } else { [CommenData showMsgError:self.navigationController.view showMsg:error.errorDescription]; } }];}-(void)updateTime{ count++; if (count>=60) { [_timer2 invalidate]; self.sendCode.text=@"重新获取验证码"; self.sendCode.userInteractionEnabled=YES; return; } //NSLog(@"更新时间"); self.sendCode.text=[NSString stringWithFormat:@"%i秒后可重新发送",60-count]; self.sendCode.userInteractionEnabled=NO;}-(void)nextAction{ //验证号码 if(self.icode.text.length!=4) { [CommenData showMsgError:self.navigationController.view showMsg:@"验证码错误"]; } else { [SMS_SDK commitVerifyCode:self.icode.text result:^(enum SMS_ResponseState state) { if (1==state) { NSLog(@"验证成功"); //下一步 修改密码 UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; self.loginPasswordController=[story instantiateViewControllerWithIdentifier:@"loginPasswordPage"]; if([self.showWho isEqualToString:@"1"]){ //修改密码 self.loginPasswordController.showWho=@"1"; }else{ //注册 self.loginPasswordController.showWho=@"2"; } self.loginPasswordController.mobile=self.mobile.text; [self.navigationController pushViewController:self.loginPasswordController animated:YES]; } else if(0==state) { NSLog(@"验证失败"); [CommenData showMsgError:self.navigationController.view showMsg:@"验证码失败"]; } }]; }}//点击空白处隐藏键盘-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.mobile resignFirstResponder]; [self.icode resignFirstResponder];}//改变输入框背景图片-(void)textFieldDidBeginEditing:(UITextField *)textField{ if (textField.tag==5) { [self.mobile setBackground:[UIImage imageNamed:@"inputlan2.png"]]; [self.icode setBackground:[UIImage imageNamed:@"inputhui2.png"]]; }else if(textField.tag==6){ [self.icode setBackground:[UIImage imageNamed:@"inputlan2.png"]]; [self.mobile setBackground:[UIImage imageNamed:@"inputhui2.png"]]; }}-(void)textFieldDidEndEditing:(UITextField *)textField{ if (textField.tag==5) { [self.mobile setBackground:[UIImage imageNamed:@"inputhui2.png"]]; }else if(textField.tag==6){ [self.icode setBackground:[UIImage imageNamed:@"inputhui2.png"]]; }}@end
0 0
- IOS 使用shareSDK发送验证码
- 利用ShareSDK集成发送短信验证码
- iOS - ShareSDK 短信验证码开发记录
- 使用ShareSDK的SMSSDK短信验证码
- ShareSdk(IOS)使用心得
- sharesdk 短信验证码
- ShareSdk验证码
- iOS-计时器发送验证码
- 使用自定义ui的ShareSDK短信验证码功能
- shareSdk集成短信验证码
- iOS GCD实现发送验证码倒计时
- iOS发送短信后验证码倒计时
- iOS关于sharesdk的集成和使用
- ios 使用ShareSDK实现分享时出错
- ios 使用ShareSDK实现分享时出错
- iOS使用ShareSDK分享显示中文
- 使用阿里大于发送短信验证码
- 使用ajax实现发送验证码业务
- system()详解
- WIN7中组件服务中的DCOM配置找不到Microsoft Excel应用程序的解决办法和
- sql特殊查询
- Spring学习笔记(五):数据库事务
- 与编程初见
- IOS 使用shareSDK发送验证码
- 【练习笔记】剑指offer-面试题4 :替换空格
- zenner WR3 真兰多功能能量积分仪 MBUS协议解析
- java中的抽象类
- linux环境变量设置错误后,如何恢复解决方案:
- 关于头文件是否参与编译的讨论
- WIN7中组件服务中的DCOM配置找不到Microsoft Excel应用程序的解决办法和
- 【opencv】opencv源码分析(一):imread、cvLoadImage、waitKey、imshow函数
- 设计模式 策略模式