The simplest iOS network request

Source: Internet
Author: User

To do iOS development, speaking of network requests, we may all coincide with the mention of AFN, you can say that everyone's network requests are packaged with AFN, AFN powerful and easy to use is indeed very good.

However, there are some problems with the version upgrade, so you have a static library that encapsulates a network request based on iOS native, allowing your line of code to implement network requests.

Based on the native iOS package of Get and post network requests, a line of code can be implemented, based on the native package, easy to use.

How to use: 1. Download the static library and import

Https://github.com/YouZhiZheShiJingCheng/YZNetWork

Import remember to tick the copy,

2. Configuration Engineering

Targets->build settings->other Linker Flags Add a-OBJC

3. Start the application

Import Header File

#import "YZNetWork.h"

Network requests

[[Yznet YZ] Ispost:yes url:@ "" withdata:@{@ "parameter": @ "number"} withsucess:^ (Nsdictionary *response) {//Request succeeded} withfalie:^ (Nserror *error) {//Request failed} andnetoff:^{//No Network}];

The first parameter indicates whether it is post, yes, yes, not no

The second parameter is the parameter of the network request, which is a dictionary with corresponding parameters and values corresponding to the parameters

The third one is the result of a successful request, and a dictionary is returned

The fourth one is the error message returned by the request failure

The last one is a situation without a network.

Remember to let the app allow access to HTTP


The simplest iOS network request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.