robertmryan / afhttpsessionoperation Goto Github PK
View Code? Open in Web Editor NEWA `NSOperation` subclass for requests added to `AFHTTPSessionManager`
License: MIT License
A `NSOperation` subclass for requests added to `AFHTTPSessionManager`
License: MIT License
*** AFHTTPSessionOperation 0x165a9220 went isFinished=YES without being started by the queue it is in
Problem occured when queue is suspending and an operation is added
@robertmryan can you do something or just explain me witch patch i can do ?
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!
app crashes at [AFURLSessionOperation completeOperation] line AFURLSessionOperation.m line 128.
Anyone faced similar problem ?
Whenever setFinished method is called which is defined in AsynchroniousOperationManager. m file. I tried to solve but it fails. This crash occured very rarely. I used AFNetworking 3.0 framework.
It would be great if the library could be found in CocoaPods.
Please add spec file as described here:
https://guides.cocoapods.org/making/making-a-cocoapod.html
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];
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.
- (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"];
}
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.
how to cancel all que and stop requests?
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
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.
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.
Is anyone else having this issue after updating their Xcode? Can you help me resolve this error?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.