Giter VIP home page Giter VIP logo

lsnetworking's Introduction

LSNetworking

Provides commonly used network processing, network status monitoring, data requests, file / picture upload and download, etc.

Introduction

The tool provides the usual network processing

  • The network request encapsulatesAFN, and the current version is 3.1.0.
  • File upload package NSURLSession

Scenes

  • Network status monitoring
  • GET / POST data request
  • Upload / download file / picture

How to use

For commonly used network requests, you can use the following methods directly

// Detects network status
[LSNetworking checkNetStatusWithBlock:^(LSNetworkStatusType status) {
   NSLog(@"current netWork: %zd", status);
}];
    
/*
demo 
   - Please replace the correct URL and parameters
   - You should use a correct URL to return to json format, the following address is returned to a HTML rather than json.
   - If your URL contains parameters, then you can use it like this
       NSDictionary *sendDic = @{
                                   @"sendParameTestKey" : @"sendParameTestValue"
       };
*/
NSString *sendURL = @"https://www.baidu.com";
[LSNetworking getOrPostWithType:GET WithUrl:sendURL params:nil success:^(id response) {
   // you can do the data processing here ...
   NSLog(@"Test response: %@", response);
} fail:^(NSError *error) {
   // Abnormal data processing
   NSLog(@"error Message: %@", error);
}];

File upload, you need to create a tool instance, and then call the object method

# pragma mark - uploadFile

/**
 Multi-file upload, you can upload text messages
 
 @param URLString      File upload address
 @param serverFileName The server receives the field name of the file
 @param filePaths      Multi-file path collection
 @param textDict       Multi-file upload when the text information
 */
- (void)uploadFilesWithURLString:(NSString *)URLString serverFileName:(NSString *)serverFileName filePaths:(NSArray *)filePaths textDict:(NSDictionary *)textDict;

/**
 Single file upload, can not upload text information
 
 @param URLString      File upload address
 @param serverFileName The server receives the field name of the file
 @param filePath       The path to the file
 */
- (void)uploadFileWithURLString:(NSString *)URLString serverFileName:(NSString *)serverFileName filePath:(NSString *)filePath;

中文介绍

工具提供了常用的网络处理

  • 其中网络请求封装了AFN,当前项目中使用到的版本为3.1.0.
  • 文件上传封装了NSURLSession

场景

  • 网络状态监测
  • GET/POST数据请求
  • 上传/下载文件/图片

使用

对于常用的网络请求,你可以直接使用如下的方式

// Detects network status
[LSNetworking checkNetStatusWithBlock:^(LSNetworkStatusType status) {
   NSLog(@"current netWork: %zd", status);
}];
    
/*
demo 
   - Please replace the correct URL and parameters
   - You should use a correct URL to return to json format, the following address is returned to a HTML rather than json.
   - If your URL contains parameters, then you can use it like this
       NSDictionary *sendDic = @{
                                   @"sendParameTestKey" : @"sendParameTestValue"
       };
*/
NSString *sendURL = @"https://www.baidu.com";
[LSNetworking getOrPostWithType:GET WithUrl:sendURL params:nil success:^(id response) {
   // you can do the data processing here ...
   NSLog(@"Test response: %@", response);
} fail:^(NSError *error) {
   // Abnormal data processing
   NSLog(@"error Message: %@", error);
}];

文件的上传,则需要先创建工具实例,再调用对象方法

# pragma mark - uploadFile

/**
 Multi-file upload, you can upload text messages
 
 @param URLString      File upload address
 @param serverFileName The server receives the field name of the file
 @param filePaths      Multi-file path collection
 @param textDict       Multi-file upload when the text information
 */
- (void)uploadFilesWithURLString:(NSString *)URLString serverFileName:(NSString *)serverFileName filePaths:(NSArray *)filePaths textDict:(NSDictionary *)textDict;

/**
 Single file upload, can not upload text information
 
 @param URLString      File upload address
 @param serverFileName The server receives the field name of the file
 @param filePath       The path to the file
 */
- (void)uploadFileWithURLString:(NSString *)URLString serverFileName:(NSString *)serverFileName filePath:(NSString *)filePath;

lsnetworking's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.