• <i id='UmWFL'><tr id='UmWFL'><dt id='UmWFL'><q id='UmWFL'><span id='UmWFL'><b id='UmWFL'><form id='UmWFL'><ins id='UmWFL'></ins><ul id='UmWFL'></ul><sub id='UmWFL'></sub></form><legend id='UmWFL'></legend><bdo id='UmWFL'><pre id='UmWFL'><center id='UmWFL'></center></pre></bdo></b><th id='UmWFL'></th></span></q></dt></tr></i><div id='UmWFL'><tfoot id='UmWFL'></tfoot><dl id='UmWFL'><fieldset id='UmWFL'></fieldset></dl></div>

      <tfoot id='UmWFL'></tfoot>

      • <bdo id='UmWFL'></bdo><ul id='UmWFL'></ul>

      <legend id='UmWFL'><style id='UmWFL'><dir id='UmWFL'><q id='UmWFL'></q></dir></style></legend>

        <small id='UmWFL'></small><noframes id='UmWFL'>

      1. 如何使用可达性类来检测有效的互联网连接?

        时间:2023-10-03
          <tbody id='QKgJj'></tbody>
        • <small id='QKgJj'></small><noframes id='QKgJj'>

          <i id='QKgJj'><tr id='QKgJj'><dt id='QKgJj'><q id='QKgJj'><span id='QKgJj'><b id='QKgJj'><form id='QKgJj'><ins id='QKgJj'></ins><ul id='QKgJj'></ul><sub id='QKgJj'></sub></form><legend id='QKgJj'></legend><bdo id='QKgJj'><pre id='QKgJj'><center id='QKgJj'></center></pre></bdo></b><th id='QKgJj'></th></span></q></dt></tr></i><div id='QKgJj'><tfoot id='QKgJj'></tfoot><dl id='QKgJj'><fieldset id='QKgJj'></fieldset></dl></div>

            • <bdo id='QKgJj'></bdo><ul id='QKgJj'></ul>
              <legend id='QKgJj'><style id='QKgJj'><dir id='QKgJj'><q id='QKgJj'></q></dir></style></legend>
              <tfoot id='QKgJj'></tfoot>
                  本文介绍了如何使用可达性类来检测有效的互联网连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 iOS 开发的新手,正在努力让reachability.h 类正常工作.这是我的视图控制器代码:

                  I'm new to iOS development and am struggling to get the reachability.h class to work. Here is my code for view controller:

                  - (void)viewWillAppear:(BOOL)animated
                  {
                      [[NSNotificationCenter defaultCenter]
                       addObserver:self 
                       selector:@selector(checkNetworkStatus:) 
                       name:kReachabilityChangedNotification 
                       object:nil];
                  
                      internetReachable = [Reachability reachabilityForInternetConnection];
                      [internetReachable startNotifier];
                  }
                  
                  - (void)checkNetworkStatus:(NSNotification *)notice {
                      NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
                      NSLog(@"Network status: %i", internetStatus);
                  }
                  

                  看起来不错,但在运行应用程序并切换到该视图时,xcode 控制台中没有出现任何内容.

                  It looks ok but nothing is appearing in the xcode console when running the app and switching to that view.

                  我正在使用可达性 2.2 和 iOS 4.2.

                  I'm using Reachability 2.2 and iOS 4.2.

                  有什么明显的我做错了吗?

                  Is there something obvious that I am doing wrong?

                  推荐答案

                  如果你想在一些代码执行之前检查可达性,你应该使用

                  EDITED: If you want to check reachability before some code execution you should just use

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

                  您还可以在某处添加可达性观察者(即在 viewDidLoad 中):

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

                  当您不再需要可达性检测时(即在 dealloc 方法中),不要忘记调用 [[NSNotificationCenter defaultCenter] removeObserver:self];.

                  Don't forget to call [[NSNotificationCenter defaultCenter] removeObserver:self]; when you no longer need reachability detection (i.e. in dealloc method).

                  这篇关于如何使用可达性类来检测有效的互联网连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iphone sdk 4.2.1 的问题 下一篇:iOS 5.0.1:如何验证文件夹是否标记为“不备份"为 iCloud?

                  相关文章

                  <i id='PGrJ1'><tr id='PGrJ1'><dt id='PGrJ1'><q id='PGrJ1'><span id='PGrJ1'><b id='PGrJ1'><form id='PGrJ1'><ins id='PGrJ1'></ins><ul id='PGrJ1'></ul><sub id='PGrJ1'></sub></form><legend id='PGrJ1'></legend><bdo id='PGrJ1'><pre id='PGrJ1'><center id='PGrJ1'></center></pre></bdo></b><th id='PGrJ1'></th></span></q></dt></tr></i><div id='PGrJ1'><tfoot id='PGrJ1'></tfoot><dl id='PGrJ1'><fieldset id='PGrJ1'></fieldset></dl></div>

                    <tfoot id='PGrJ1'></tfoot>
                    <legend id='PGrJ1'><style id='PGrJ1'><dir id='PGrJ1'><q id='PGrJ1'></q></dir></style></legend>
                      <bdo id='PGrJ1'></bdo><ul id='PGrJ1'></ul>

                      <small id='PGrJ1'></small><noframes id='PGrJ1'>