Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Bugfix: didn't work if index.html wasn't in the docRoot #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ios/AppDelegate+WKWebViewPolyfill.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void) createWindowAndStartWebServer:(BOOL) startWebServer {

// Note: the embedded webserver is still needed for iOS 9. It's not needed to load index.html,
// but we need it to ajax-load files (file:// protocol has no origin, leading to CORS issues).
NSString *directoryPath = myMainViewController.wwwFolderName;
NSString *directoryPath = myMainViewController.docRoot;
_webServer = [[GCDWebServer alloc] init];
_webServerOptions = [NSMutableDictionary dictionary];

Expand Down Expand Up @@ -79,12 +79,12 @@ - (void)addHandlerForPath:(NSString *) path {
if ([fileLocation hasPrefix:path]) {
fileLocation = [appDataFolder stringByAppendingString:request.URL.path];
}

fileLocation = [fileLocation stringByReplacingOccurrencesOfString:FileSchemaConstant withString:@""];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileLocation]) {
return nil;
}

return [GCDWebServerFileResponse responseWithFile:fileLocation byteRange:request.byteRange];
}
];
Expand Down
1 change: 1 addition & 0 deletions src/ios/MyMainViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@property (nonatomic, readwrite, copy) NSString* uiWebViewLS;
@property (nonatomic, readwrite, copy) NSString* wkWebViewLS;
@property (nonatomic, readwrite, copy) NSString* docRoot;

@property (nonatomic, strong) NSURL* url;
@property (nonatomic, assign) BOOL pageLoaded;
Expand Down
7 changes: 4 additions & 3 deletions src/ios/MyMainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ - (id)init
NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
_targetExistsLocally = [[NSFileManager defaultManager]
fileExistsAtPath:startFilePath];
startFilePath = [startFilePath stringByDeletingLastPathComponent];
self.wwwFolderName = startFilePath;
NSRange range = [startFilePath rangeOfString:self.startPage options:NSBackwardsSearch];
NSString* docRoot = [startFilePath substringToIndex:range.location];
self.docRoot = docRoot;
self.alreadyLoaded = false;
}

Expand Down Expand Up @@ -393,7 +394,7 @@ - (void)viewDidLoad
if ([self.webView respondsToSelector:@selector(setKeyboardDisplayRequiresUserAction:)]) {
[self.webView setValue:[NSNumber numberWithBool:keyboardDisplayRequiresUserAction] forKey:@"keyboardDisplayRequiresUserAction"];
}

if (!keyboardDisplayRequiresUserAction) {
[self keyboardDisplayDoesNotRequireUserAction];
}
Expand Down