zoukankan      html  css  js  c++  java
  • asihttprequest简单异步

    调试环境:
    ASIHTTPRequest版本1.8.1-61 2011-9-19修复版
    Xcode版本4.2.1
    iOS5.0
    Mac OS X10.7.1

    在此代码仅仅捣鼓异步的初步处理
    1、需要实现协议接口

    ASIHTTPRequestDelegate


    主要requestFailed,requestFinished之类的接口

    2、调用的时候,建议启动异步request的对象和异步处理的对象分开定义

    下面我的代码是启动异步和异步处理定义在一起

    代码:

    @interface AsynBaseDeal : NSObject<ASIHTTPRequestDelegate>

    - (void)LoadImage:(NSString *)strUrl;

    @end
    @implementation AsynBaseDeal

    - (id)init
    {
    self = [super init];
    if (self)
    {
    }

    return self;
    }

    - (void)dealloc
    {
    [super dealloc];
    }

    - (void)LoadImage:(NSString *)strUrl
    {
    if (strUrl)
    {
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:strUrl]];

    [request setDelegate:self];
    [request startAsynchronous];
    }
    }

    - (void)requestFailed:(ASIHTTPRequest *)request
    {
    NSLog(@"error :%@" ,[request error]);
    }

    - (void)requestFinished:(ASIHTTPRequest *)request
    {
    NSLog(@"finish :%@ ,%d" ,[request responseData] ,request.responseEncoding);
    }
    @end


    在使用中,我把AsynBaseDeal对象定义为UIApplication层面的成员变量来用的,这样避免了在异步处理结束前就释放了对应的处理对象




    无论生活、还是技术,一切都不断的学习和更新~~~努力~
  • 相关阅读:
    NOI2005 维护数列(splay)
    傻子代码行列式
    Matrix-tree定理 spoj HIGH
    Boruvka算法求最小生成树
    Codeforces 521 E cycling city
    欧拉回路 uoj117
    BZOJ1146: [CTSC2008]网络管理Network
    我的OI生涯番外篇
    主席树+dfs SPOJ BZOJ2588 Count on a tree
    动态主席树 优化版
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/2298196.html
Copyright © 2011-2022 走看看