Coder Social home page Coder Social logo

afhttpsessionoperation's People

Contributors

gagoyal avatar priore avatar robertmryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

afhttpsessionoperation's Issues

batch requests

Hi, thank you for your great job!
But i encountered a problem that the method bacthOfRequests: has been delete when i updated the AFNetworking 3.0 .

I read your code , maybe your SessionOperation can help me, Could you make some suggests for me ?

Thank you!

Not Work for dependency request

I want the first request finished then call the second request, but the AFHTTPSessionOperation not work at all. What is the problem.

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 3;
queue.name = @"AFHTTPSessionManager queue";

NSOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
    NSLog(@"All done");
}];

// guest request
NSString *device_os = [NSString stringWithFormat:@"iOS %@",[[UIDevice currentDevice] systemVersion]];
NSString *device_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
NSDictionary *parameters = @{@"client_id":Client_ID_iOS,
                             @"client_secret":Client_Secret_iOS,
                             @"device_id":device_id,
                             @"device_os":device_os};
NSString *requestString = [NSString stringWithFormat:@"%@tokens/guest",tokenURL];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSOperation *tokenOP = [AFHTTPSessionOperation operationWithManager:manager HTTPMethod:@"POST" URLString:requestString parameters:parameters uploadProgress:nil downloadProgress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
    NSLog(@"finished token");

    NSLog(@"%@",responseObject);
    NSDictionary *dic = responseObject;
    NSTimeInterval expiredInterval = [[dic objectForKey:@"expires_in"] doubleValue] - 300;
    NSString *guestToken = [NSString stringWithFormat:@"%@ %@",
                            [dic objectForKey:@"token_type"],
                            [dic objectForKey:@"guest_token"]];
    [TMarkTokenManager setGuestToken:guestToken expireTime:expiredInterval];
    [manager.requestSerializer setValue:[TMarkTokenManager getGuestToken] forHTTPHeaderField:@"Authorization"];
    NSLog(@"%@",[TMarkTokenManager getGuestToken]);

} failure:^(NSURLSessionDataTask *task, NSError *error) {
    NSLog(@"failed 1 - error = %@", error.localizedDescription);
    //[queue cancelAllOperations];
}];


// LogIn Request
NSDictionary *Loginparameters = @{@"login_id":login_id,
                                  @"password":password};
NSString *LogInrequestString = [NSString stringWithFormat:@"%@accounts/login/native",
                                tokenURL];
//[manager.requestSerializer setValue:[TMarkTokenManager getGuestToken] forHTTPHeaderField:@"Authorization"];
NSOperation *LogingRequestOp = [AFHTTPSessionOperation operationWithManager:manager HTTPMethod:@"POST" URLString:LogInrequestString parameters:Loginparameters uploadProgress:nil downloadProgress:nil success:^(NSURLSessionDataTask *task, id responseObject) {

    NSLog(@"finished Login!");
} failure:^(NSURLSessionDataTask *task, NSError *error) {

    NSLog(@"failed 1 - error = %@", error.localizedDescription);
}];


[LogingRequestOp addDependency:tokenOP];

[queue addOperation:tokenOP];
[queue addOperation:LogingRequestOp];
//[queue addOperations:@[tokenOP, LogingRequestOp] waitUntilFinished:false];

[[NSOperationQueue mainQueue] addOperation:completionOperation];

No method to create operation from NSURLRequest

Is there any specific reason that you have not provided a method to create task using dataTaskWithRequest:completionHandler. My issue is that I want to use your operation and I have NSURLRequest already with HTTPBody set in that. Now using the API that you provided, I cannot set HTTPBody in request. So I want to use dataTaskWithRequest:completionHandler as it accepts parameter of type NSURLRequest directly.

Please let me know if you faced any issues in implementing it or it is by choice that you did not provide an interface to accept request directly.

Why the location of 'if' in 'setExecuting' and 'setFinished' is different?

- (void)setExecuting:(BOOL)executing {
    if (_executing != executing) {  // "if" is here
        [self willChangeValueForKey:@"isExecuting"];
        @synchronized(self) {
            _executing = executing;
        }
        [self didChangeValueForKey:@"isExecuting"];
    }
}

- (void)setFinished:(BOOL)finished {
    [self willChangeValueForKey:@"isFinished"];
    @synchronized(self) {
        if (_finished != finished) {       // "if" is here
            _finished = finished;
        }
    }
    [self didChangeValueForKey:@"isFinished"];
}

AFHTTPSessionOperation not run on background

Thanks for your library.
I used AFHTTPSessionOperation and add it to NSOperationQueue but it always run on main thread. I want that task will be processed on background thread. Please give me some advice for this.

This is my code:

   // create opertation
    NSOperation *operation = [AFHTTPSessionOperation operationWithManager:_sessionManager HTTPMethod:@"POST" URLString:apiURL parameters:params uploadProgress: nil downloadProgress: nil 
    success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        @autoreleasepool{
            if(responseObject) {
                completion(responseObject,nil);
            }
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        @autoreleasepool{
            NSLog(@"Error: %@", error);
            completion(nil,error);
        }
    }];
    [_opertationQueue addOperation:operation];

Thanks for you help.

(minor) missing parameters in 'auto-filled' method sigs

first of all, great work here... this is greatly easing my (late to the party) migration from AFNetworking 2 -> 3. much appreciated!

just a little super minor thing. here's a screenshot to assist in the description. The 'blocks' are missing the actual parameters and only have the types defined. assuming that's not on purpose. take a look at the success and failure ones specifically

screen shot 2016-01-26 at 1 46 14 pm

Thread safety

Shouldn't you be wrapping setExecuting: and setFinished: into @synchronized() block?

Both setters are called from main thread and background thread (from -(void)start). NSOperationQueue creates separate thread for asynchronous tasks.

Semantic issue in library after updating xcode

Hello, thank you for this great library! It has been a great help in migrating AFNetworking 2 to 3 in our project.

But recently after updating Xcode to 8.3.1, I am suddenly getting compiler errors in AFURLSessionOperation.m about a semantic issue.
The error is

Sending 'void (^ _Nullable __strong)(NSProgress *__strong)' to parameter of incompatible type 'NSProgress *__autoreleasing *'.

Here is a screenshot of the affected methods.
d395e55530040936fcf3f821618d6c58

Is anyone else having this issue after updating their Xcode? Can you help me resolve this error?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.