Skip to content

Commit

Permalink
Check if handler is running to avoid crashes for timed out requests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasMerz committed Oct 21, 2019
1 parent 1733694 commit 4d38f74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ios/IONAssetHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@property (nonatomic, strong) NSString * basePath;
@property (nonatomic, strong) NSString * scheme;
@property (nonatomic) Boolean isRunning;

-(void)setAssetPath:(NSString *)assetPath;
- (instancetype)initWithBasePath:(NSString *)basePath andScheme:(NSString *)scheme;
Expand Down
11 changes: 8 additions & 3 deletions src/ios/IONAssetHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (instancetype)initWithBasePath:(NSString *)basePath andScheme:(NSString *)sche

- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)urlSchemeTask
{
self.isRunning = true;
Boolean loadFile = true;
NSString * startPath = @"";
NSURL * url = urlSchemeTask.request.URL;
Expand Down Expand Up @@ -77,9 +78,12 @@ - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur
};
}

[urlSchemeTask didReceiveResponse:response];
[urlSchemeTask didReceiveData:data];
[urlSchemeTask didFinish];
// Do not use urlSchemeTask if it has been closed in stopURLSchemeTask
if(self.isRunning) {
[urlSchemeTask didReceiveResponse:response];
[urlSchemeTask didReceiveData:data];
[urlSchemeTask didFinish];
}
}] resume];
} else {
startPath = self.basePath;
Expand Down Expand Up @@ -115,6 +119,7 @@ - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur

- (void)webView:(nonnull WKWebView *)webView stopURLSchemeTask:(nonnull id<WKURLSchemeTask>)urlSchemeTask
{
self.isRunning = false;
NSLog(@"stop");
}

Expand Down

0 comments on commit 4d38f74

Please sign in to comment.