diff --git a/README.md b/README.md index 9efd45f..c7b988c 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/plugin.xml b/plugin.xml index 13e86c4..e0a23ed 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="0.5.0"> WKWebView Polyfill diff --git a/src/ios/AppDelegate+WKWebViewPolyfill.m b/src/ios/AppDelegate+WKWebViewPolyfill.m index 04497da..6f83887 100755 --- a/src/ios/AppDelegate+WKWebViewPolyfill.m +++ b/src/ios/AppDelegate+WKWebViewPolyfill.m @@ -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]; } diff --git a/src/ios/MyMainViewController.m b/src/ios/MyMainViewController.m index cb16cd6..a7ec91f 100755 --- a/src/ios/MyMainViewController.m +++ b/src/ios/MyMainViewController.m @@ -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 + }]; } @@ -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 @@ -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]; @@ -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.