天天看點

iOS中 WGAFN_網絡監控 技術分享

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。

需要用到第三方afnetworking/svprogresshud

appdelegate.m

#import "afnetworking.h"  

#import "svprogresshud.h"  

代碼實作比較簡單:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {  

    // override point for customization after application launch.  

    [svprogresshud setdefaultmasktype:svprogresshudmasktypenone];  

    [svprogresshud setringthickness:8];  

    // 1. 獲得網絡監控的管理者  

    afnetworkreachabilitymanager *manager = [afnetworkreachabilitymanager sharedmanager];  

    // 2. 設定網絡狀态改變後的處理  

    [manager setreachabilitystatuschangeblock:^(afnetworkreachabilitystatus status) {  

        // 當網絡狀态改變了, 就會調用這個block  

        switch (status) {  

            case afnetworkreachabilitystatusunknown:  

                nslog(@"未知網絡");  

                break;  

            case afnetworkreachabilitystatusnotreachable:  

                nslog(@"沒有網絡(斷網)");  

            case afnetworkreachabilitystatusreachableviawwan:  

                nslog(@"手機自帶網絡");  

            case afnetworkreachabilitystatusreachableviawifi:  

                nslog(@"wifi");  

                [svprogresshud showsuccesswithstatus:@"wifi"];  

        }  

    }];  

    // 3. 開始監控  

    [manager startmonitoring];  

    return yes;  

}  

最終效果:

iOS中 WGAFN_網絡監控 技術分享

原文位址:http://blog.csdn.net/qq_31810357/article/details/49563167

繼續閱讀