mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 09:42:23 +02:00
Error bad status while downloading launcher
This commit is contained in:
parent
5d316a9fd6
commit
d8fec15842
2 changed files with 36 additions and 3 deletions
|
@ -3,6 +3,8 @@
|
|||
@interface DownloadLauncher : NSObject<NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLDownloadDelegate> {
|
||||
}
|
||||
|
||||
@property (readonly) bool didBecomeDownloadTask;
|
||||
|
||||
- (void) downloadLauncher:(NSString*) launcherUrl;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,6 +8,13 @@ static const NSString *kIOError = @"IOError";
|
|||
|
||||
@implementation DownloadLauncher
|
||||
|
||||
-(id)init {
|
||||
if ((self = [super init]) != nil) {
|
||||
_didBecomeDownloadTask = false;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) downloadLauncher:(NSString*)launcherUrl {
|
||||
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:launcherUrl]
|
||||
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
||||
|
@ -16,8 +23,8 @@ static const NSString *kIOError = @"IOError";
|
|||
|
||||
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
|
||||
NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request];
|
||||
[downloadTask resume];
|
||||
NSURLSessionDataTask *task = [defaultSession dataTaskWithRequest:request];
|
||||
[task resume];
|
||||
}
|
||||
|
||||
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
|
||||
|
@ -45,6 +52,25 @@ static const NSString *kIOError = @"IOError";
|
|||
}
|
||||
}
|
||||
|
||||
-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
|
||||
didReceiveResponse:(NSURLResponse *)response
|
||||
completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
|
||||
{
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
||||
NSURLSessionResponseDisposition disposition = NSURLSessionResponseBecomeDownload;
|
||||
if (httpResponse.statusCode != 200) {
|
||||
NSLog(@"expected statusCode 200, got %ld", (long)httpResponse.statusCode);
|
||||
disposition = NSURLSessionResponseCancel;
|
||||
}
|
||||
completionHandler(disposition);
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
|
||||
didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask
|
||||
{
|
||||
_didBecomeDownloadTask = true;
|
||||
}
|
||||
|
||||
-(void)URLSession:(NSURLSession*)session downloadTask:(NSURLSessionDownloadTask*)downloadTask didFinishDownloadingToURL:(NSURL*)location {
|
||||
NSLog(@"Did finish downloading to url");
|
||||
@try {
|
||||
|
@ -95,9 +121,14 @@ static const NSString *kIOError = @"IOError";
|
|||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession*)session task:(NSURLSessionTask*)task didCompleteWithError:(NSError*)error {
|
||||
NSLog(@"completed; error: %@", error);
|
||||
if (error) {
|
||||
if (_didBecomeDownloadTask && [task class] == [NSURLSessionDataTask class]) {
|
||||
return;
|
||||
}
|
||||
NSLog(@"couldn't complete download: %@", error);
|
||||
[[Launcher sharedLauncher] displayErrorPage];
|
||||
} else {
|
||||
NSLog(@"finished downloading Launcher");
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue