Web 服务应用程序的 iOS 应用程序架构

发布于 2024-11-19 00:41:35 字数 514 浏览 6 评论 0原文

我正在开发一个应用程序,它是客户端并与网络服务进行通信。我正在使用 Reachability 类检查互联网连接。如果可用,我将布尔值设置为“是”,将“否”设置为默认值。

在我的应用程序委托的 didFinishLaunchingWithOptions 方法中,我获取一个单例对象并将其添加用于观察网络状态变化,以便它可以快速将 bool 转换为 YES。

当我的第一个 viewDidLoad 时,我尝试从 Web 服务 getToken ,因此我检查 internetConnection 是否可用,并且它总是返回 NO,因为我的对象获取我尝试获取令牌后收到通知。我认为使用延迟的表演者不是一个好主意,所以我该如何处理这种情况。提前谢谢..

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 use a delayed performer, so how can I handle that situation. Thank in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最笨的告白 2024-11-26 00:41:36

在您的情况下,我使用了 ASIHTTPRequest 库来检查请求是否到达服务器。 ASIHTTPRequest 提供了很多方法,包括这个:

-(void)requestFinished:(ASIHTTPRequest *)request

要测试连接,您可以执行以下操作:

-(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];
    }


}

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];
    }


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文