Latest 1.0.1
Homepage https://github.com/QianChia/QDownload
License MIT
Platforms ios 7.0, requires ARC
Authors

Logo

  • A simple encapsulation of files to download.

GitHub:QianChia | Blog:QianChia(Chinese)


Installation

From CocoaPods

  • pod 'QDownload'

Manually

  • Drag all source files under floder QDownload to your project.
  • Import the main header file:#import "QDownload.h"

Examples

QReachability

  • QReachability methods

    
        // 开始监听网络状态
    
        + (void)q_startMonitoringForDomain:(nullable NSString *)domain 
                              statusChange:(void (^)(NetworkStatus status))networkStatus;
    
        + (void)q_startMonitoringForAddress:(nullable NSString *)address 
                               statusChange:(void (^)(NetworkStatus status))networkStatus;
    
        // 开始监听网络状态
        + (void)q_startMonitoring;
    
        // 停止监听网络状态
        + (void)q_stopMonitoring;
    
        // 获取网络是否可用
        + (BOOL)q_isReachable;
    
        // 获取 WiFi 网络是否可用
        + (BOOL)q_isReachableViaWiFi;
    
        // 获取蜂窝网络是否可用
        + (BOOL)q_isReachableViaWWAN;
    
  • The use of QReachability

    
        // 开始监听网络状态
        [QReachability q_startMonitoringForDomain:nil statusChange:^(NetworkStatus status) {
    
            NSString *statusString = @"";
            UIImage *image = nil;
    
            switch (status) {
    
                case NotReachable: {
                    statusString = @"Access Not Available";
                    image = [UIImage imageNamed:@"stop-32.png"] ;
                    break;
                }
                case ReachableViaWWAN: {
                    statusString = @"Reachable WWAN";
                    image = [UIImage imageNamed:@"WWAN5.png"];
                    break;
                }
                case ReachableViaWiFi: {
                    statusString = @"Reachable WiFi";
                    image = [UIImage imageNamed:@"Airport.png"];
                    break;
                }
            }
            self.netStatusLabel.text = statusString;
            self.netStatusImageView.image = image;
        }];
    
        // 域名
        NSString *hostName = @"www.apple.com";
    
        // 开始监听网络状态
        [QReachability q_startMonitoringForDomain:hostName statusChange:^(NetworkStatus status) {
    
            NSString *statusString = @"";
            UIImage *image = nil;
    
            switch (status) {
    
                case NotReachable: {
                    statusString = @"Access Not Available";
                    image = [UIImage imageNamed:@"stop-32.png"] ;
                    break;
                }
                case ReachableViaWWAN: {
                    statusString = @"Reachable WWAN";
                    image = [UIImage imageNamed:@"WWAN5.png"];
                    break;
                }
                case ReachableViaWiFi: {
                    statusString = @"Reachable WiFi";
                    image = [UIImage imageNamed:@"Airport.png"];
                    break;
                }
            }
            self.netStatusLabel.text = statusString;
            self.netStatusImageView.image = image;
        }];
        // IP 地址
        NSString *hostAddress = @"202.108.22.5";
    
        // 开始监听网络状态
        [QReachability q_startMonitoringForAddress:hostAddress statusChange:^(NetworkStatus status) {
    
            NSString *statusString = @"";
            UIImage *image = nil;
    
            switch (status) {
    
                case NotReachable: {
                    statusString = @"Access Not Available";
                    image = [UIImage imageNamed:@"stop-32.png"] ;
                    break;
                } 
                case ReachableViaWWAN: {
                    statusString = @"Reachable WWAN";
                    image = [UIImage imageNamed:@"WWAN5.png"];
                    break;
                }
                case ReachableViaWiFi: {
                    statusString = @"Reachable WiFi";
                    image = [UIImage imageNamed:@"Airport.png"];
                    break;
                }
            }
            self.netStatusLabel.text = statusString;
            self.netStatusImageView.image = image;
        }];
    
        // 获取网络是否可用
        BOOL isReachable = [QReachability q_isReachable];
    
        // 获取 WiFi 网络是否可用
        BOOL isReachableViaWiFi = [QReachability q_isReachableViaWiFi];
    
        // 获取蜂窝网络是否可用
        BOOL isReachableViaWWAN = [QReachability q_isReachableViaWWAN];
    
    
        // 开始监听网络状态
        [QReachability q_startMonitoring];
    
        // 停止监听网络状态
        [QReachability q_stopMonitoring];
    

QWebImage

  • QWebImage methods

    
        // 设置 Web 图像
        - (void)q_setWebImageWithURLStr:(NSString *)urlStr;
    
  • The use of QWebImage

    
        // 设置网络图片
        [cell.imageView q_setWebImageWithURLStr:dataModel.icon];
    

QSessionDownloader

  • QSessionDownloader methods

    
        // 创建单例类对象
        + (instancetype)defaultDownloader;
    
        // 创建下载
        - (void)q_downloadWithURL:(NSURL *)url
                         progress:(void (^)(float progress))progress
                        successed:(void (^)(NSString *targetPath))successed
                           failed:(void (^)(NSError *error))failed;
    
        // 暂停下载
        - (void)q_pauseWithURL:(NSURL *)url;
    
        // 取消下载
        - (void)q_cancelWithURL:(NSURL *)url;
    
  • The use of QSessionDownloader

    
        // 开始下载
    
        [[QSessionDownloader defaultDownloader] q_downloadWithURL:url progress:^(float progress) {
    
            dispatch_async(dispatch_get_main_queue(), ^{
                ];
            });
    
        } successed:^(NSString *targetPath) {
    
            NSLog(@"文件下载成功:%@", targetPath);
    
        } failed:^(NSError *error) {
    
            if ([error.userInfo[NSLocalizedDescriptionKey] isEqualToString:@"pauseDownload"]) {
    
                NSLog(@"暂停下载");
    
            } else if ([error.userInfo[NSLocalizedDescriptionKey] isEqualToString:@"cancelDownload"]) {
    
                NSLog(@"取消下载");
    
            } else {
    
                NSLog(@"文件下载失败:%@", error.userInfo[NSLocalizedDescriptionKey]);
            }
        }];
    
        // 暂停下载
    
        [[QSessionDownloader defaultDownloader] q_pauseWithURL:url];
    
        // 取消下载
    
        [[QSessionDownloader defaultDownloader] q_cancelWithURL:url];
    

QAFNetworking

  • QAFNetworking methods

    
        // 创建单例类对象
        + (instancetype)sharedNetworkTools;
    
  • The use of QAFNetworking

    
        // AFNetworking 数据请求
    
        NSString *urlStr = @"http://192.168.88.200:8080/MJServer/video?type=JSON";
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
    
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:config];
    
        [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
    
            if (error == nil && responseObject != nil) {
                NSLog(@"success: %@ --- %@", responseObject, [responseObject class]);
            } else {
                NSLog(@"failure: %@", error);
            }
        }] resume];
    
    
        // QAFNetworking 封装
    
        NSString *urlStr = @"http://192.168.88.200:8080/MJServer/video?type=JSON";
    
        [[QAFNetworking sharedNetworkTools] GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
            if (responseObject != nil) {
                NSLog(@"success: %@ --- %@", responseObject, [responseObject class]);
            }
    
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
            NSLog(@"failure: %@", error);
        }];
    

Latest podspec

{
    "name": "QDownload",
    "version": "1.0.1",
    "license": "MIT",
    "authors": {
        "QianChia": "[email protected]"
    },
    "summary": "A simple encapsulation of files to download",
    "homepage": "https://github.com/QianChia/QDownload",
    "source": {
        "git": "https://github.com/QianChia/QDownload.git",
        "tag": "1.0.1"
    },
    "requires_arc": true,
    "platforms": {
        "ios": "7.0"
    },
    "source_files": "QDownload/QDownload.h",
    "public_header_files": "QDownload/QDownload.h",
    "subspecs": [
        {
            "name": "QReachability",
            "source_files": "QDownload/QReachability/QReachability.{h,m}",
            "subspecs": [
                {
                    "name": "Reachability",
                    "source_files": "QDownload/QReachability/Reachability/Reachability.{h,m}"
                }
            ]
        },
        {
            "name": "QWebImage",
            "source_files": "QDownload/QWebImage/*.{h,m}"
        },
        {
            "name": "QSessionDownloader",
            "source_files": "QDownload/QSessionDownloader/*.{h,m}"
        },
        {
            "name": "QAFNetworking",
            "source_files": "QDownload/QAFNetworking/QAFNetworking.{h,m}",
            "subspecs": [
                {
                    "name": "AFNetworking",
                    "source_files": "QDownload/QAFNetworking/AFNetworking/*.{h,m}"
                }
            ]
        }
    ]
}

Pin It on Pinterest

Share This