开发者

iOS Application Architecture for a Web Service App

I am developing an application which is a client and is communicating with a web service. I am checking internet connection with Reachability class. If its avaliable, I set a bool as YES, its NO as default.

In my application delegate's didFinishLaunchingWithOptions method, I grab a singleton object and add it for observing network status changes so it can turn bool into YES quickly.

When my first viewDidLoad, I try to getToken from web service so I check if internetConnection is avaliable and it always returns NO because my object gets a notification after I tried to get a token. I don't think its a good idea u开发者_运维问答se a delayed performer, so how can I handle that situation. Thank in advance..


in your case, i have used the ASIHTTPRequest library to check either the request was reaching the server or not. The ASIHTTPRequest offers a lot of methods including this one :

-(void)requestFinished:(ASIHTTPRequest *)request

To test the connection, you can do something like this :

-(void)requestFinished:(ASIHTTPRequest *)request{


if(request.responseStatusCode==200)
    {
          //successfull connection, do what you need
        }
else {
      //failed request sent, display the correspondant error

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your app name" 
                                                        message:@"Unexpected error" 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜