ios 版得用户登录编写
2013-10-17 13:19
309 查看
#import
@interface ViewController :
UIViewController
{
UITextField
*m_tf_user;//用户名
UITextField
*m_tf_pass;//用户密码
NSMutableData *m_data;
//存储返回得数据
}
@property(strong,nonatomic)IBOutlet UITextField *m_tf_user; //连接
@property(strong,nonatomic)IBOutlet UITextField
*m_tf_pass;
@property NSMutableData
*m_data;
-(IBAction)dologin:(id)sender;//同步联网登陆
-(IBAction)dologin02:(id)sender;//异步联网登陆
@end
----------------------------
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize
m_tf_user;
@synthesize m_tf_pass;
@synthesize m_data;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional
setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//
Dispose of any resources that can be recreated.
}
-(IBAction)dologin:(id)sender{
//
1.创建url
NSString *s_url=[[NSString alloc]initWithFormat:@"http://10.2.145.69/logincheck.php?us=%@&ps=%@",m_tf_user.text,m_tf_pass.text];
NSLog(@"%@",s_url);
NSURL
*url=[[NSURL alloc]initWithString:s_url];
//2.创建请求对象
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
//3.发送请求返回数据
NSError *err;
NSData *data=[NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:&err];
//4.处理接受到的数据
if
(data.length>0) {
NSString *s_result=[[NSString
alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",s_result);
if ([s_result
rangeOfString:@"ok"].length>0)
{
UIAlertView * alert=[[UIAlertView
alloc]initWithTitle:@"登录结果"
message:@"登陆成功"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
else{
UIAlertView * alert=[[UIAlertView
alloc]initWithTitle:@"登录结果"
message:@"登陆失败"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
}
else
{
UIAlertView *
alert=[[UIAlertView alloc]initWithTitle:@"登录结果"
message:@"登陆失败"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
}
-(IBAction)dologin02:(id)sender{
//
1.创建url
NSString *s_url=[[NSString alloc]initWithFormat:@"http://10.2.145.69/logincheck.php?us=%@&ps=%@",m_tf_user.text,m_tf_pass.text];
NSLog(@"%@",s_url);
NSURL
*url=[[NSURL alloc]initWithString:s_url];
//2.创建请求对象
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
//3.发送数据请求
m_data=[[NSMutableData alloc]init];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
//接收数据
- (void)connection:(NSURLConnection
*)connection didReceiveData:(NSData *)data{
[
m_data appendData:data];
}
//数据接受完成
-
(void)connectionDidFinishLoading:(NSURLConnection *)connection{
printf("data recive OK");
NSString *s_result=[[NSString alloc]initWithData:m_data
encoding:NSUTF8StringEncoding];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"登录结果"
message:s_result delegate:nil cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
@end
@interface ViewController :
UIViewController
{
UITextField
*m_tf_user;//用户名
UITextField
*m_tf_pass;//用户密码
NSMutableData *m_data;
//存储返回得数据
}
@property(strong,nonatomic)IBOutlet UITextField *m_tf_user; //连接
@property(strong,nonatomic)IBOutlet UITextField
*m_tf_pass;
@property NSMutableData
*m_data;
-(IBAction)dologin:(id)sender;//同步联网登陆
-(IBAction)dologin02:(id)sender;//异步联网登陆
@end
----------------------------
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize
m_tf_user;
@synthesize m_tf_pass;
@synthesize m_data;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional
setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//
Dispose of any resources that can be recreated.
}
-(IBAction)dologin:(id)sender{
//
1.创建url
NSString *s_url=[[NSString alloc]initWithFormat:@"http://10.2.145.69/logincheck.php?us=%@&ps=%@",m_tf_user.text,m_tf_pass.text];
NSLog(@"%@",s_url);
NSURL
*url=[[NSURL alloc]initWithString:s_url];
//2.创建请求对象
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
//3.发送请求返回数据
NSError *err;
NSData *data=[NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:&err];
//4.处理接受到的数据
if
(data.length>0) {
NSString *s_result=[[NSString
alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",s_result);
if ([s_result
rangeOfString:@"ok"].length>0)
{
UIAlertView * alert=[[UIAlertView
alloc]initWithTitle:@"登录结果"
message:@"登陆成功"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
else{
UIAlertView * alert=[[UIAlertView
alloc]initWithTitle:@"登录结果"
message:@"登陆失败"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
}
else
{
UIAlertView *
alert=[[UIAlertView alloc]initWithTitle:@"登录结果"
message:@"登陆失败"delegate:nil
cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
}
-(IBAction)dologin02:(id)sender{
//
1.创建url
NSString *s_url=[[NSString alloc]initWithFormat:@"http://10.2.145.69/logincheck.php?us=%@&ps=%@",m_tf_user.text,m_tf_pass.text];
NSLog(@"%@",s_url);
NSURL
*url=[[NSURL alloc]initWithString:s_url];
//2.创建请求对象
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];
//3.发送数据请求
m_data=[[NSMutableData alloc]init];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
//接收数据
- (void)connection:(NSURLConnection
*)connection didReceiveData:(NSData *)data{
[
m_data appendData:data];
}
//数据接受完成
-
(void)connectionDidFinishLoading:(NSURLConnection *)connection{
printf("data recive OK");
NSString *s_result=[[NSString alloc]initWithData:m_data
encoding:NSUTF8StringEncoding];
UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"登录结果"
message:s_result delegate:nil cancelButtonTitle:@"知道了"
otherButtonTitles:nil, nil];
[alert show];
}
@end
相关文章推荐
- 苹果向公测用户发布 iOS&nbsp…
- linux 限制用户登录
- loadrunner 参数化,用户登录
- 用户 'sa' 登录失败。该用户与可信…
- struts2 简单注解配置实现用户登录
- 一步一步实现iOS QQ第三方登录
- iOS 添加自定义字体方法详解
- mysql 服务器端关于用户连接方面的…
- IOS APP 真机测试步骤
- IOS 7 Xcode 5 免IDP证书 真机调试
- 发布iOS应用(xcode5)到App St…
- CocoaPods的安装和使用 IOS程…
- 【转】linux svn 切换用户
- Linux下配置vsftpd和虚拟用户 成功
- ios 修改系统NavigationContr…
- iOS sharekit分享
- 解决方案:用户'sa'登录失败,忘记sa密码[SqlServer]
- MSSQL2008 用户'sa'登录失败。错误18456
- JavaScriptCookie&PHPCookie实现用户登录信息自动填入
- ios实现用户登录的保存密码功能