小秋的家

          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
          主站蜘蛛池模板: 柏乡县| 宣城市| 阿巴嘎旗| 开江县| 武山县| 上蔡县| 尼木县| 土默特右旗| 睢宁县| 象山县| 武宣县| 彰化市| 哈巴河县| 晋城| 错那县| 永宁县| 英德市| 吉水县| 鹤岗市| 鄯善县| 乡城县| 凤冈县| 鲁山县| 四平市| 汉中市| 商丘市| 芷江| 砚山县| 牡丹江市| 资中县| 贡山| 将乐县| 元朗区| 新昌县| 毕节市| 巴中市| 合山市| 北流市| 遂溪县| 鲁甸县| 昌宁县|