nsscreencast / comments

Public comments on NSScreencast.com
0 stars 0 forks source link

AFNetworking 2.0 - NSScreencast #85

Open subdigital opened 3 years ago

subdigital commented 3 years ago

Written on 05/28/2015 19:54:19

URL: https://nsscreencast.com/episodes/91-afnetworking-2-0

subdigital commented 3 years ago

originally written by Akash on 10/17/2013 20:17:57

Very Nice. How can we build a task dependent on another task. Or let's say if I want to restart a task, in case of any failure?
Also would love to see a future episode on Oauth2 Login with AFNetworking, as AFOauth2Client is obselete.

subdigital commented 3 years ago

originally written by Cezar C on 10/18/2013 05:37:03

I could be wrong but I thought with AFNetworking the callback are run on the main thread unless a thread is otherwise specified : http://stackoverflow.com/qu...

I could be wrong!

subdigital commented 3 years ago

originally written by subdigital on 10/18/2013 15:28:46

Nope, you are correct. I just checked the source (https://github.com/AFNetwor... and the completion block is indeed called on the mainQueue unless you specify otherwise.

Thanks for the clarification!

subdigital commented 3 years ago

originally written by subdigital on 10/18/2013 15:30:00

Do you have a specific example of a case where you'd want to have dependent requests? I don't think I've ever had a need for this, but I could have been missing a cool pattern.

OAuth2 sounds like a good idea. Can you suggest it at http://nsscreencast.uservoi... so it can collect some votes?

subdigital commented 3 years ago

originally written by djibouti33 on 10/18/2013 16:04:27

Another great screencast Ben.

In my experience using 2.0 so far, I've found you don't have to test for the status code in your success block because AFHTTPResponseSerializer (which is a superclass of AFJSONResponseSerializer) has an acceptableStatusCodes property which defaults to anything in the 200 range. Anything outside of that will fall into your failure block.

http://cocoadocs.org/docset...

subdigital commented 3 years ago

originally written by Akash on 10/19/2013 06:30:25

Well one such example of dependent request is Oauth2's refreshToken. Where if an access token is expired, and we are calling a session task for getting the data, but it needs to revoke the refresh token to get a new access token and then retry the original task for getting the data. It was easily possible in AFNetworking 1.x where you could create a RequestOperation, but if you are working with AFHTTPSessionManager, I don't see a way to retry the task.

OAuth2 episode would cover the above scenario as well, and instead using an external service like instagram for OAuth2, you can go for a ruby gem DoorKeeper and create your own OAuth2 server.

Another example for dependent requests is we did call a task, but it depends on a data that haven't been fetched yet. so the task goes to the parent task to fetch the data and then resume the current task.

subdigital commented 3 years ago

originally written by Gerry on 10/21/2013 23:52:58

I believe AFNetworking already dispatches the callbacks on the main thread for requests so don't have to add that `dispatch_async(dispatch_get_main_queue()` noise in your success & failure callbacks.

subdigital commented 3 years ago

originally written by subdigital on 10/22/2013 03:26:56

Yep you're right. Thanks for the clarification!

subdigital commented 3 years ago

originally written by gutte on 11/05/2013 16:20:33

Trying here as well.. My issue with afnetworking 2.0 and http post-multipart: http://stackoverflow.com/qu...

subdigital commented 3 years ago

originally written by Ohm on 11/12/2013 18:19:28

How do you get the statusCode from the Failure block ?

subdigital commented 3 years ago

originally written by subdigital on 11/12/2013 21:04:58

You have to cast the url response to a NSHTTPURLResponse.


Sent from Mailbox for iPad

subdigital commented 3 years ago

originally written by Binh on 12/03/2013 18:03:18

How would you get access to the actual JSON response if you were posting to a Rails app for example? I get 3 keys back in the [error userInfo], NSErrorFailingURLKey, AFNetworkingOperationFailingURLResponseErrorKey and NSLocalizedDescription. But nothing seems to contain the actual JSON with the error messages in them.

subdigital commented 3 years ago

originally written by subdigital on 12/03/2013 18:31:29

This is sort of a contentious point in the project right now. I've read that you can get this by inspecting the userInfo:

http://i.stack.imgur.com/Cr...

But if this doesn't work for you then you may have to eschew the GET/PUT/POST methods in favor of dataTaskForRequest... methods so you can handle the response yourself.

Feel free to chime in here if you think this should be provided:
https://github.com/AFNetwor...

(This was closed, but seems to have gathered a bit of a following for folks running into the same issue)

subdigital commented 3 years ago

originally written by Алексей Медведев on 01/14/2014 10:28:43

How can i add ssl certificate in _sharedClient for HTTPS requests? I have the following code, but it's still no effect!

PS I have .p12 cert installed in IOS simulator - browser can get access to the server.

subdigital commented 3 years ago

originally written by subdigital on 01/14/2014 18:56:24

Can you elaborate? I’m not sure I understand your question.

subdigital commented 3 years ago

originally written by Алексей Медведев on 01/14/2014 19:14:20

I'm trying to make a request to https api server, with authentication through ssl certificate.

subdigital commented 3 years ago

originally written by subdigital on 01/14/2014 19:29:54

If you’re trying to do SSL pinning, there’s a different video for that. If you’re just trying to use a self-signed URL to validate access to a server, I don’t have any specific advise for you (I’ve never done this before), however I’m sure there’s some resources out there for how to accomplish this.

subdigital commented 3 years ago

originally written by imorti on 01/22/2014 02:06:28

Have an issue where images just aren't showing up...anyone else?

subdigital commented 3 years ago

originally written by subdigital on 01/22/2014 02:23:00

Make sure you're using the right image view. If you accidentally use the cell's default image view and you don't have an image set when the cell is laid out, then it will hide the image view altogether.

subdigital commented 3 years ago

originally written by Ivan Dikic on 01/22/2014 12:27:03

Hello,

these lines of code,are they necessary?

cell.artworkImageView.image = nil;
[cell.artworkImageView cancelImageRequestOperation];

Will the ARC take care for the first line?
And cancelImageRequestOperation is automatically called inside category method.

By the way, super site, I really like the jingle :)

subdigital commented 3 years ago

originally written by imorti on 01/22/2014 15:35:45

Thanks. Turns out I was using the wrong record param. had URL capitalized.

subdigital commented 3 years ago

originally written by Guillermo Arias on 01/25/2014 20:32:21

How can I retry a request using this approach? In a previous episode you showed how to do this with AFHTTPRequestOperation, I would like to do the same with AFHTTPSessionManager

subdigital commented 3 years ago

originally written by CRDave on 03/07/2014 11:44:21

Any one like to comment on this problem : http://stackoverflow.com/qu...

subdigital commented 3 years ago

originally written by Stephane Cedroni on 03/17/2014 23:01:13

Hi, has anyone had some issues with other APIs than Itunes (which works perfectly fine)?
When trying to change only the NSURL *baseURL and parameters dictionary, I get a

ERROR: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x14e96130 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

while I get a JSON object if I pass that same URL in the web browser...

subdigital commented 3 years ago

originally written by Angel Solorio on 05/12/2014 19:21:58

After adding a third party framework called "Estate.framework" to my project I got this error when compiling:

duplicate symbol _OBJC_CLASS_$_Reachability in:
/Users/ASolorio/Library/Developer/Xcode/DerivedData/Vodafone-bkfpwkbyxayspxgufxyrtnrgkizx/Build/Intermediates/Vodafone.build/Debug-iphone...
/Users/ASolorio/Documents/Projects/Vodafone/iOS/Estate_Mobile_Vodafone/Estate.framework/Estate(Reachability.o)
...
...
ld: 72 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems that the Estate.framework is using AFNetworking too and there is a conflict with my AFNetworking framework that I am using through Cocoa Pods in my project. Somebody knows how to solve this issue?
Thanks in advance...

subdigital commented 3 years ago

originally written by subdigital on 05/12/2014 19:28:03

They should not be using AFNetworking statically linked like that. They should either replace AFNetworking with a native NSURLSession solution or rename the symbols before including. There’s not much you can do at this point.

subdigital commented 3 years ago

originally written by Angel Solorio on 05/12/2014 21:18:51

Thank you.