zoukankan      html  css  js  c++  java
  • AFnetworking监测网络变化(iOS网络提示)

    #import <Foundation/Foundation.h>
    #import "AFHTTPSessionManager.h"
    @interface AFAppDotNetAPIClient : AFHTTPSessionManager
    + (instancetype)sharedClient;
     
    @end
    #import "AFAppDotNetAPIClient.h"
    static NSString * const AFAppDotNetAPIBaseURLString =@"https://api.app.net/";
    @implementation AFAppDotNetAPIClient
    + (instancetype)sharedClient {
        static AFAppDotNetAPIClient *_sharedClient = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _sharedClient = [[AFAppDotNetAPIClient alloc]initWithBaseURL:[NSURLURLWithString:AFAppDotNetAPIBaseURLString]];
            _sharedClient.securityPolicy = [AFSecurityPolicypolicyWithPinningMode:AFSSLPinningModeNone]; 
            [_sharedClient.reachabilityManagersetReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatusstatus) {
                switch (status) {
                    case AFNetworkReachabilityStatusReachableViaWWAN:
                //手机自带网络可用(GPRS)
                        NSLog(@"-------AFNetworkReachabilityStatusReachableViaWWAN------");
                        break;
                    case AFNetworkReachabilityStatusReachableViaWiFi:
                       //WIFI可用
                        NSLog(@"-------AFNetworkReachabilityStatusReachableViaWiFi------");
                        break;
                    case AFNetworkReachabilityStatusNotReachable:
                        //无网络连接
                        NSLog(@"-------AFNetworkReachabilityStatusNotReachable------");
                        break;
                    default:
                        break;
                }
            }];
            [_sharedClient.reachabilityManager startMonitoring];
        });
        return _sharedClient;
    }
    @end 
  • 相关阅读:
    使用数组实现简单线性表功能
    解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析
    Entity Framework with NOLOCK
    64位CentOS 6.0下搭建LAMP环境
    如何正确看待Linq的DistinctBy扩展和ForEach扩展
    jQuery最佳实践
    大话数据结构-树
    hdu2534-Score
    WKE——Webkit精简的纯C接口的浏览器
    WM_ERASEBKGND官方解释(翻译),以及Delphi里所有的使用情况(就是绘制窗口控件背景色,并阻止进一步传递消息)
  • 原文地址:https://www.cnblogs.com/liyanyan/p/5235874.html
Copyright © 2011-2022 走看看