iOS Development Afnetworking 3.0 usage problems encountered

Source: Internet
Author: User

A while ago wrote an iOS development afnetworking 3.0.4 Use this article, is the basic usage, yesterday in the use of time again appeared several questions, specially two record, hoped can help everybody!

Question One

I am to do a mobile phone verification code function, make a network request, verification code also sent to me, the backstage also told me that the request was successful, but my side of the print information displayed directly into the wrong callback ... Such as:


Verification code get return format problem

The error is that the return type is inconsistent , and later the reason is to return the format of the problem (although the background tells me that the JSON returned) needs to be added on this sentence:

    //如果报接受类型不一致请替换一致text/html或别的    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

Solve this problem!

Question Two

Because I used AFN, this lazy directly to the previous code copied a bit, and then use the background with me to say no past parameters, my side to determine the parameters of what are written, but also did not write wrong, but still can not wear the past parameters. So I looked up the code and found that there were two words in the code:


Declaring the return type

The declaration request and the returned data are JSON. The problem is in the first sentence, because I declare that passed the parameter is JSON format, but I write the format is not JSON, AFN my parameters filtered, so the background that I passed the parameter is null. (This is my own understanding, there is no place to ask the great God to correct it)
Solution I am. Two direct comments (because I know the JSON is returned, the second one is the same).
Here, the first sentence plus is definitely wrong, the second sentence does not matter ...

At present, the problem is so two, and later if you encounter the words to add.

PS: Again, now a lot of friends are still using AFN2.0 version, it is based on nsurlconnection write, but Apple in Xcode7 abandoned this (although can use), instead of Nsurlsession, And AFN3.0 is based on nsurlsession to do, AFN3.0 in the deletion of nsurlconnection-based things, such as the previous common afurlconnectionoperation, Afhttprequestoperation, Afhttprequestoperationmanager, AFN 3.0 version now officially supports iOS 7, Mac OS x 10.9, WatchOS 2, TvOS 9 and Xcode 7, so Think still with new good, in case completely remove nsurlconnection, that is all to blind ...

AFN 2.0 upgrade to the latest version of the API, you can see this text specifically transition.



Original link: http://www.jianshu.com/p/95a368c6f7de Thanks for sharing

iOS Development Afnetworking 3.0 usage problems encountered

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.