AFNetworking Crash Course

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

AFNetworking Crash Course

Postby rwenderlich » Mon Mar 18, 2013 11:00 am

This is the official thread to discuss the following blog post: AFNetworking Crash Course
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2175
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 350 times

Re: AFNetworking Crash Course

Postby Matthew » Mon Mar 18, 2013 7:30 pm

Hi Scott,
your crash course if wonderful! I really loved it...
Just one thing: what about using AFNetworking with OAuth?
There are some extensions like AFOAuth1Client and AFOAuth2Client but I couldn't find anything on the web.
Can you check them out?
Thank you and congrats again!
Matteo
------------------------------
Matteo Del Vecchio
Founder and Developer at Matthew Labs
Website | Twitter | Facebook | Google+ | GitHub
------------------------------
User avatar
Matthew
n00b
 
Posts: 4
Joined: Sat Jun 11, 2011 11:23 am
Location: Pietravairano, CE, Italy
Has thanked: 0 time
Been thanked: 0 time

Re: AFNetworking Crash Course

Postby jvanlint » Tue Mar 19, 2013 7:32 am

Scott,
Nice tute!

One thing you might mention. AFNEtworking has a nasty habit of not recognising web servers that don't support application/json MIME type. This causes it give an error. I could never get the property of the object to work I ended up modifying the .m file but if making a call to a url that has .json as the extension and the server does not have a json MIME type set up AFNetworking won't recognise the file.
jvanlint
Uber Haxx0r
 
Posts: 116
Joined: Wed Oct 19, 2011 9:26 pm
Has thanked: 1 time
Been thanked: 17 times

Re: AFNetworking Crash Course

Postby ssherwood » Tue Mar 19, 2013 9:24 am

jvanlint wrote:Scott,
Nice tute!

One thing you might mention. AFNEtworking has a nasty habit of not recognising web servers that don't support application/json MIME type. This causes it give an error. I could never get the property of the object to work I ended up modifying the .m file but if making a call to a url that has .json as the extension and the server does not have a json MIME type set up AFNetworking won't recognise the file.



Thanks Javanlint.

I can't say I have come across that is your server side script returning the correct MIME type? I typically just add it to the response header in my php scripts, header("Content-Type: application/json");

Thanks,
Scott
Last edited by ssherwood on Tue Mar 19, 2013 9:27 am, edited 1 time in total.
ssherwood
Team Member
Baby Hacker
 
Posts: 6
Joined: Sun Mar 17, 2013 10:21 pm
Has thanked: 0 time
Been thanked: 0 time

Re: AFNetworking Crash Course

Postby ssherwood » Tue Mar 19, 2013 9:26 am

Matthew wrote:Hi Scott,
your crash course if wonderful! I really loved it...
Just one thing: what about using AFNetworking with OAuth?
There are some extensions like AFOAuth1Client and AFOAuth2Client but I couldn't find anything on the web.
Can you check them out?
Thank you and congrats again!
Matteo


Hello Matthew,
I have not used them but I can take a look.

Thanks,
Scott
ssherwood
Team Member
Baby Hacker
 
Posts: 6
Joined: Sun Mar 17, 2013 10:21 pm
Has thanked: 0 time
Been thanked: 0 time

Re: AFNetworking Crash Course

Postby Marc » Tue Mar 19, 2013 4:01 pm

Hello,

Tutorial uses a deprecated method:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

Deprecated in iOS 6.0
locationManager:didUpdateToLocation:fromLocation:
Tells the delegate that a new location value is available. (Deprecated in iOS 6.0. Use locationManager:didUpdateLocations: instead.)

Regards,
Marc
Marc
n00b
 
Posts: 2
Joined: Tue Oct 23, 2012 8:39 am
Has thanked: 0 time
Been thanked: 0 time

Re: AFNetworking Crash Course

Postby snackdog » Tue Mar 19, 2013 4:22 pm

Thanks for the tutorial! Aside from the deprecated CLLocationManager method, I had to change parser:didEndElement:namespaceURI:qualifiedName: because it was creating an NSArray instead of a mutable one and then trying to add an object to it. Maybe I mistyped something but here is the updated method with the change highlighted in bold:


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([qName isEqualToString:@"current_condition"] || [qName isEqualToString:@"request"]) {
[self.xmlWeather setObject:[NSMutableArray arrayWithObject:self.currentDictionary] forKey:qName];
self.currentDictionary = nil;
}

else if ([qName isEqualToString:@"weather"]) {
NSMutableArray *array = [self.xmlWeather objectForKey:@"weather"];
if (!array) {
array = [NSMutableArray array];
}

[array addObject:self.currentDictionary];
[self.xmlWeather setObject:array forKey:@"weather"];

self.currentDictionary = nil;
}

else if ([qName isEqualToString:@"value"]) {
// ignore value tags -- they only appear in the two conditions below
}

else if ([qName isEqualToString:@"weatherDesc"] || [qName isEqualToString:@"weatherIconUrl"]) {
[self.currentDictionary setObject:[NSArray arrayWithObject:[NSDictionary dictionaryWithObject:self.outString forKey:@"value"]] forKey:qName];
}

else {
[self.currentDictionary setObject:self.outString forKey:qName];
}

self.elementName = nil;
}
snackdog
Baby Hacker
 
Posts: 7
Joined: Thu Apr 05, 2012 11:58 pm
Has thanked: 3 times
Been thanked: 0 time

Re: AFNetworking Crash Course

Postby reidnez » Tue Mar 19, 2013 10:47 pm

First I want to thank you for an excellent tutorial. Secondly, I'm encountering a problem that I wonder if anyone might help me with.

When I run the app after implementing the HTTPClient section, and I tap either "HTTP POST" or "HTTP GET" in the action sheet, the app crashes in numberOfRowsInSection, at this line (with "all exceptions" breakpoint enabled):

NSArray *upcomingWeather = [self.weather upcomingWeather];

Debugger output is as follows:

-[__NSCFData upcomingWeather]: unrecognized selector sent to instance...

There are no compiler warnings at all. It seems that the upcomingWeather method in the NSDictionary (weather_package) category is not being recognized, but I'm not sure how to fix it. The class extension .h and .m files are in my project, and the .m is listed under "compile sources" in my build phases...tried the usual steps of quitting XCode and doing a clean, to no avail. Any thoughts? I really want to finish the tutorial!

Thanks!
-Reid
I am available for contracting/consulting (PM me) and for one-on-one tutoring at http://www.codementor.io/reid
My personal blog can be found at http://www.cocoatouchedme.com
User avatar
reidnez
Team Member
Forum Subject Matter Expert
 
Posts: 644
Joined: Fri Oct 12, 2012 8:47 pm
Has thanked: 11 times
Been thanked: 167 times

Re: AFNetworking Crash Course

Postby akonakov » Wed Mar 20, 2013 12:40 pm

Hm... can't resolve the problem coming after adding AFNetworking folder to the project. Even after adding

Code: Select all
#import <MobileCoreServices/MobileCoreServices.h>
#import <SystemConfiguration/SystemConfiguration.h>


to the Prefix.pch, I still can't run the application with two warnings:

.../AFNetworking/AFHTTPClient.h:83:2: SystemConfiguration framework not found in project, or not included in precompiled header. Network reachability functionality will not be available.
.../AFNetworking/AFHTTPClient.h:88:2: MobileCoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.

and an error:

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 254

What's wrong with it? AFNetworking was cloned from github just today. XCode 4.6.1. Please, help :)
User avatar
akonakov
Hacker
 
Posts: 35
Joined: Wed May 02, 2012 5:21 am
Has thanked: 3 times
Been thanked: 2 times

Re: AFNetworking Crash Course

Postby faabalia » Wed Mar 20, 2013 4:31 pm

Congratulation for your tutorial is fantastic. I have one question, can it be used with web services developed with SOAP? If not do you know a way to consume SOAP Web services.

Thank yo very much!!!!! :D
faabalia
Hacker
 
Posts: 33
Joined: Thu Apr 26, 2012 12:45 pm
Has thanked: 4 times
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests