AFNetworking Post Request with json feedback

前端 未结 2 841
滥情空心
滥情空心 2020-12-14 05:14

I am using AFNetworking and creating a post request for which I require json feedback. The code below works however I have two main questions; where do I release the Activit

相关标签:
2条回答
  • 2020-12-14 05:31

    Why not use this instead?

        [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    

    Hence there's no need to alloc and init

    Can't say much on the other codes, just started out learning objective-C and AFNetworking.. :)

    Regards, Steve0hh

    0 讨论(0)
  • 2020-12-14 05:34

    I know this question is a bit old, but I still wanted to contribute.

    As steveOhh said, you should use [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES] to turn on the activity network indicator. It is a singleton, and hence it doesn't require you to manually alloc-init and release. As to the other question, I noticed you are missing some parameters in your block calls, also, you can do this, which is much cleaner code:

    NSURL *url = [NSURL URLWithString:@"mysite/user/signup"];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:[NSURLRequest requestWithURL:url] success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        // your success code here
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        // your failure code here
    }];
    
    [operation start]; // start your operation directly, unless you really need to use a queue
    
    0 讨论(0)
提交回复
热议问题