小秋的家

          home

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(9)

          我參與的團(tuán)隊

          搜索

          •  

          最新評論

          //在程序的啟動處,開啟通知

          - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

          {

            //.....

          //開啟網(wǎng)絡(luò)狀況的監(jiān)聽

          [[NSNotificationCenter defaultCenteraddObserver:self

                   selector:@selector(reachabilityChanged:)

               namekReachabilityChangedNotification

             objectnil];

          hostReach = [[Reachability reachabilityWithHostName:@"www.google.com"retain];//可以以多種形式初始化

          [hostReach startNotifier];  //開始監(jiān)聽,會啟動一個run loop

                  [self updateInterfaceWithReachabilityhostReach];

            //.....

          }


          // 連接改變

          - (void) reachabilityChanged: (NSNotification* )note

          {

          Reachability* curReach = [note object];

          NSParameterAssert([curReach isKindOfClass: [Reachability class]]);

          [self updateInterfaceWithReachability: curReach];

          }


          //處理連接改變后的情況

          - (void) updateInterfaceWithReachability: (Reachability*) curReach

          {

              //對連接改變做出響應(yīng)的處理動作。

                  NetworkStatus status = [curReach currentReachabilityStatus];

              

          if (status == NotReachable) {  //沒有連接到網(wǎng)絡(luò)就彈出提實況

          UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"My App Name"

                                        message:@"NotReachable"

                                        delegate:nil

                                        cancelButtonTitle:@"YES" otherButtonTitles:nil];

                                        [alert show];

                                        [alert release];

          }

          }

          posted on 2012-12-05 11:05 棋劍小秋 閱讀(243) 評論(0)  編輯  收藏 所屬分類: iPhone
          主站蜘蛛池模板: 九龙县| 澄城县| 清河县| 开鲁县| 林甸县| 涞水县| 新干县| 泗水县| 安丘市| 思南县| 攀枝花市| 车险| 哈尔滨市| 福州市| 灌南县| 鄂尔多斯市| 攀枝花市| 大渡口区| 岳阳县| 仁化县| 红河县| 平潭县| 连山| 新乡市| 无极县| 利川市| 白河县| 青浦区| 博白县| 遵化市| 武宁县| 苍溪县| 泊头市| 永定县| 上思县| 惠东县| 景洪市| 同心县| 阳泉市| 杭锦后旗| 灵璧县|