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

Commit

Permalink
#131 Incompatible with iOS9 Public Beta 1
Browse files Browse the repository at this point in the history
#127 iOS 9 without local webserver
  • Loading branch information
EddyVerbruggen committed Aug 23, 2015
1 parent 8bfc216 commit 3d6a115
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ $ cordova prepare
No need for anything else - you can now open the project in XCode 6 if you like.

## 4. Changelog
* __0.4.0__ Compatibility with Telerik LiveSync and LivePatch. Disabled the horizontal and vertical scrollbars. Added support for config.xml property DisableCrashRecovery (default false).
* __0.5.0__ iOS9 (beta) compatibility, keyboard scroll fix, white keyboard background if no specific color is specified (was black).
* __0.4.0__ Compatibility with Telerik LiveSync and LivePatch. Disabled the horizontal and vertical scrollbars. Added support for `config.xml` property `DisableCrashRecovery` (default `false`).
* __0.3.8__ Adding a way to access files in '/Library/' and '/Documents/' (simply use those prefixes), thanks #88!
* __0.3.7__ Custom URL Schemes did not work, see #98, also this version includes crash recovery, thanks #62!
* __0.3.6__ Bind embedded webserver to localhost so it can't be reached from the outside, thanks #64!
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.telerik.plugins.wkwebview"
version="0.4.0">
version="0.5.0">

<name>WKWebView Polyfill</name>

Expand Down
45 changes: 24 additions & 21 deletions src/ios/AppDelegate+WKWebViewPolyfill.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ - (void) createWindowAndStartWebServer:(BOOL) startWebServer {
[self.window makeKeyAndVisible];
appDataFolder = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByDeletingLastPathComponent];

// Initialize Server environment variables
NSString *directoryPath = myMainViewController.wwwFolderName;
_webServer = [[GCDWebServer alloc] init];
_webServerOptions = [NSMutableDictionary dictionary];

// Add GET handler for local "www/" directory
[_webServer addGETHandlerForBasePath:@"/"
directoryPath:directoryPath
indexFilename:nil
cacheAge:60
allowRangeRequests:YES];

[[NSNotificationCenter defaultCenter] postNotificationName:ServerCreatedNotificationName object: @[myMainViewController, _webServer]];

[self addHandlerForPath:@"/Library/"];
[self addHandlerForPath:@"/Documents/"];

// Initialize Server startup
if (startWebServer) {
[self startServer];
// webserver no longer needed for iOS 9, yay!
if (!IsAtLeastiOSVersion(@"9.0")) {
// Initialize Server environment variables
NSString *directoryPath = myMainViewController.wwwFolderName;
_webServer = [[GCDWebServer alloc] init];
_webServerOptions = [NSMutableDictionary dictionary];

// Add GET handler for local "www/" directory
[_webServer addGETHandlerForBasePath:@"/"
directoryPath:directoryPath
indexFilename:nil
cacheAge:60
allowRangeRequests:YES];

[[NSNotificationCenter defaultCenter] postNotificationName:ServerCreatedNotificationName object: @[myMainViewController, _webServer]];

[self addHandlerForPath:@"/Library/"];
[self addHandlerForPath:@"/Documents/"];

// Initialize Server startup
if (startWebServer) {
[self startServer];
}
}

// Update Swizzled ViewController with port currently used by local Server
[myMainViewController setServerPort:_webServer.port];
}
Expand Down
27 changes: 27 additions & 0 deletions src/ios/MyMainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,15 @@ - (void)loadURL:(NSURL*)URL
[CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
_userAgentLockToken = lockToken;
[CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken];

// This is only for iOS 9 SDK
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
[self.wkWebView loadFileURL:URL allowingReadAccessToURL:URL];
#else
NSURLRequest* appReq = [NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[self.wkWebView loadRequest:appReq];
#endif

}];
}

Expand Down Expand Up @@ -251,6 +258,11 @@ - (void)viewDidLoad
appURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.wwwFolderName, self.startPage]];
}

// iOS9 (runtime) compatibility
if (IsAtLeastiOSVersion(@"9.0")) {
appURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", self.wwwFolderName, self.startPage]];
}

// // Fix the iOS 5.1 SECURITY_ERR bug (CB-347), this must be before the webView is instantiated ////

NSString* backupWebStorageType = @"cloud"; // default value
Expand Down Expand Up @@ -298,6 +310,7 @@ - (void)viewDidLoad

// Configure WebView
self.wkWebView.navigationDelegate = self;
self.wkWebView.UIDelegate = self;

// register this viewcontroller with the NSURLProtocol, only after the User-Agent is set
[CDVURLProtocol registerViewController:self];
Expand Down Expand Up @@ -537,8 +550,22 @@ - (WKWebView*)newCordovaWKWebViewWithFrame:(CGRect)bounds wkWebViewConfig:(WKWeb
return cordovaView;
}


/*
#pragma mark WKNavigationDelegate implementation
// allow opening links like mailto: / tel:
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
*/


#pragma mark WKNavigationDelegate implementation
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
// It's safe to release the lock even if this is just a sub-frame that's finished loading.
Expand Down

0 comments on commit 3d6a115

Please sign in to comment.