mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +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> {
|
@interface DownloadLauncher : NSObject<NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLDownloadDelegate> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property (readonly) bool didBecomeDownloadTask;
|
||||||
|
|
||||||
- (void) downloadLauncher:(NSString*) launcherUrl;
|
- (void) downloadLauncher:(NSString*) launcherUrl;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -8,6 +8,13 @@ static const NSString *kIOError = @"IOError";
|
||||||
|
|
||||||
@implementation DownloadLauncher
|
@implementation DownloadLauncher
|
||||||
|
|
||||||
|
-(id)init {
|
||||||
|
if ((self = [super init]) != nil) {
|
||||||
|
_didBecomeDownloadTask = false;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) downloadLauncher:(NSString*)launcherUrl {
|
- (void) downloadLauncher:(NSString*)launcherUrl {
|
||||||
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:launcherUrl]
|
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:launcherUrl]
|
||||||
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
||||||
|
@ -16,8 +23,8 @@ static const NSString *kIOError = @"IOError";
|
||||||
|
|
||||||
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||||
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
|
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
|
||||||
NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request];
|
NSURLSessionDataTask *task = [defaultSession dataTaskWithRequest:request];
|
||||||
[downloadTask resume];
|
[task resume];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
|
-(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 {
|
-(void)URLSession:(NSURLSession*)session downloadTask:(NSURLSessionDownloadTask*)downloadTask didFinishDownloadingToURL:(NSURL*)location {
|
||||||
NSLog(@"Did finish downloading to url");
|
NSLog(@"Did finish downloading to url");
|
||||||
@try {
|
@try {
|
||||||
|
@ -95,9 +121,14 @@ static const NSString *kIOError = @"IOError";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)URLSession:(NSURLSession*)session task:(NSURLSessionTask*)task didCompleteWithError:(NSError*)error {
|
- (void)URLSession:(NSURLSession*)session task:(NSURLSessionTask*)task didCompleteWithError:(NSError*)error {
|
||||||
NSLog(@"completed; error: %@", error);
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
if (_didBecomeDownloadTask && [task class] == [NSURLSessionDataTask class]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSLog(@"couldn't complete download: %@", error);
|
||||||
[[Launcher sharedLauncher] displayErrorPage];
|
[[Launcher sharedLauncher] displayErrorPage];
|
||||||
|
} else {
|
||||||
|
NSLog(@"finished downloading Launcher");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue