短信验证:
加入友盟SDK
添加:
在自己的友盟里创建应用获得MOBAppKey、MOBAppSecret
ViewController.h页面:
添加了两个分页面:
#import “ViewController.h”
#import “oneViewController.h”
#import “twoViewController.h”
@interface ViewController ()
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
oneViewController *one = [oneViewController new];
UINavigationController *oneNav = [[UINavigationController alloc]initWithRootViewController:one];
oneNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"aa" image:[UIImage imageNamed:@"aa"] selectedImage:[UIImage imageNamed:@"aa"]];
twoViewController *two = [twoViewController new];
UINavigationController *twoNav = [[UINavigationController alloc]initWithRootViewController:two];
twoNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"bb" image:[UIImage imageNamed:@"bb"] selectedImage:[UIImage imageNamed:@"bb"]];
self.viewControllers = @[oneNav,twoNav];
}
@end
第一个页面:
导航右标题跳转到fbViewController.h
#import “oneViewController.h”
#import “fbViewController.h”
@interface oneViewController ()
@end
@implementation oneViewController
(void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发布" style:UIBarButtonItemStylePlain target:self action:@selector(dian)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"未登录" style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];
self.view.backgroundColor = [UIColor redColor];
UISearchBar * sea = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
sea.placeholder =@"请输入搜索的商品";
self.navigationItem.titleView = sea;
}
(void)dian{
[self.navigationController pushViewController:[fbViewController new] animated:YES];
}
fbViewController.h跳转页面:
在.m中创建属性:
@interface fbViewController : UIViewController
//创建属性
@property(nonatomic,strong)NSString *provie;
@end
.h代码:
短信验证跳转popViewController.h
#import “fbViewController.h”
#import “popViewController.h”
@interface fbViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView * tbv;
NSArray * arr;
NSArray * imarr;
}
@end
@implementation fbViewController
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//设置导航标题
self.navigationItem.title = @"登录推荐更精准";
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tbv.dataSource = self;
tbv.delegate = self;
arr = @[@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹"];
imarr = @[@"111",@"222",@"333",@"444",@"555",@"666"];
UIView * uiv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
uiv.backgroundColor = [UIColor blackColor];
UIImageView * ima = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 100, 80)];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(70, 50, 60, 60)];
UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(190, 50, 60, 60)];
UIButton *btn3 = [[UIButton alloc]initWithFrame:CGRectMake(310, 50, 60, 60)];
[btn setBackgroundImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
btn.layer.masksToBounds=YES;
btn.layer.cornerRadius=30;
[btn2 setBackgroundImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
btn2.layer.masksToBounds=YES;
btn2.layer.cornerRadius=30;
[btn3 setBackgroundImage:[UIImage imageNamed:@"3"] forState:UIControlStateNormal];
btn3.layer.masksToBounds=YES;
btn3.layer.cornerRadius=30;
[ima addSubview:btn];
[ima addSubview:btn2];
[ima addSubview:btn3];
[btn3 addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
UIImageView * imag = [[UIImageView alloc]initWithFrame:CGRectMake(0, 230, self.view.frame.size.width, 70)];
imag.image = [UIImage imageNamed:@"hh"];
[uiv addSubview:imag];
[uiv addSubview:btn];
[uiv addSubview:btn2];
[uiv addSubview:btn3];
tbv.tableHeaderView = uiv;
tbv.rowHeight = 50;
[self.view addSubview:tbv];
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}
cell.imageView.image = [UIImage imageNamed:imarr[indexPath.row]];
cell.textLabel.text = arr[indexPath.row];
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(350, 0, 40, 40)];
lab.text = @">";
lab.textColor = [UIColor lightGrayColor];
[cell addSubview:lab];
return cell;
}
-(void)click{
popViewController *pop=[popViewController new];
[self.navigationController pushViewController:pop animated:YES];
}
@end
popViewController.h短信验证页面:
#import “popViewController.h”
#import <SMS_SDK/SMSSDK.h>
@interface popViewController ()
{
UITextField *text;
UITextField *text2;
}
@end
@implementation popViewController
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(170, 220, 100, 50)];
label.text = @"账号注册";
label.font = [UIFont systemFontOfSize:23];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(75, 555, 400, 30)];
label2.text = @"□我已阅读并同意“用户协议”和”隐私政策“";
label2.font = [UIFont systemFontOfSize:15];
UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(165, 600, 100, 40)];
label3.text = @"免密码登录";
label3.font = [UIFont systemFontOfSize:17];
[self.view addSubview:label];
[self.view addSubview:label2];
[self.view addSubview:label3];
text2 = [[UITextField alloc]initWithFrame:CGRectMake(70, 300, 200, 50)];
text2.backgroundColor = [UIColor yellowColor];
[text2 setText:@"手机号"];
[self.view addSubview:text2];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(270, 300, 100, 50)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"发送验证码" forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
text = [[UITextField alloc]initWithFrame:CGRectMake(70, 400, 300, 50)];
text.backgroundColor = [UIColor yellowColor];
[text setText:@"请输入验证码"];
[self.view addSubview:text];
UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(70, 500, 300, 50)];
btn2.backgroundColor = [UIColor redColor];
[btn2 setTitle:@"注册" forState:UIControlStateNormal];
[self.view addSubview:btn2];
[btn2 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click{
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:text2.text zone:@"86" result:^(NSError *error) {
if (!error)
{
NSLog(@"成功");
// 请求成功
}
else
{
NSLog(@"失败");
// error
}
}];
}
-(void)click2{
[SMSSDK commitVerificationCode:text.text phoneNumber:text2.text zone:@"86" result:^(NSError *error) {
if (!error)
{
NSLog(@"成功");
// 验证成功
}
else
{
NSLog(@"失败");
// error
}
}];
}
@end