Tôi đã triển khai thành công NSOperationQueue trong ứng dụng.Làm thế nào để tiếp tục thời gian ra hoạt động NSOperationQueue trong iOS?
Tôi có một hàng đợi hoạt động có thể có 1000 NSOperations như dưới đây.
@interface Operations : NSOperation
@end
@implementation Operations
- (void)main
{
NSURL *url = [NSURL URLWithString:@"Your URL Here"];
NSString *contentType = @"application/json";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSError *err = nil;
NSData *body = [NSJSONSerialization dataWithJSONObject:postVars options:NSJSONWritingPrettyPrinted error:&err];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%lu", (unsigned long)body.length] forHTTPHeaderField: @"Content-Length"];
[request setTimeoutInterval:60];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *resData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
}
@end
Bây giờ cho hàng đợi đó, tôi sẽ thêm tất cả 1000 hoạt động cùng một lúc. Tôi thêm hoạt động như dưới đây.
Operations *operation = [[Operations alloc]init];
[downloadQueue addOperation:operation];
Bây giờ những gì xảy ra khoảng thời gian là 60 như [request setTimeoutInterval:60]
Vì vậy, suy nghĩ như sau 60 giây nếu 300 hoạt động ra 1000 hoạt động kết thúc sau đó 700 hoạt động khác được ném thời gian yêu cầu ra lỗi.
Vì vậy, tôi nên làm gì trong trường hợp này.
Tôi có thể tiếp tục các hoạt động không thành công không? Hoặc tôi một lần nữa nên làm cho hoạt động và thêm nó trong hàng đợi.
Có cơ chế nào tốt hơn cơ chế này không?
Bạn có thể vui lòng cung cấp một số tham chiếu mà tôi nên theo dõi không? –
@JayeshSojitra chắc chắn: [NSURLConnectionDelegate documentation] (https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/), [NSURLKết nối với Hướng dẫn di chuyển NSURLSession] (https: //www.objc. io/issue/5-ios7/from-nsurlconnection-to-nsurlsession /) – JAL