首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ios中检测网络可用性

在ios中检测网络可用性
EN

Stack Overflow用户
提问于 2015-02-18 12:53:56
回答 1查看 57关注 0票数 0

我想要一个应用程序是在IOS中完成。当网络丢失时,应用程序必须向用户发出通知。是否可以使用Objective C检查网络状态?这是不是有很多工作?

我是ios开发的新手,编写代码的人说这需要几个小时才能写完。

此外,我想为ios电子名片共享脚本。开发人员表示需要5天时间才能完成任务。

有人能在这方面帮我吗?我厌倦了听到他身边的许多借口,无法继续下去。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-02-18 17:47:44

代码语言:javascript
复制
 If you want to check reachability before some code execution you should just use..You can use reachability class for checking network status..



   Reachability *reachability = [Reachability reachabilityForInternetConnection];    
   NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    if (internetStatus != NotReachable) {
     //my web-dependent code
     }
     else {
      //there-is-no-connection warning
     }

  You can also add a reachability observer somewhere (i.e. in viewDidLoad):

   Reachability *reachabilityInfo;
   [[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(myReachabilityDidChangedMethod)
                                         name:kReachabilityChangedNotification
                                       object:reachabilityInfo];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28576233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档