Request Permission for Camera and Library in iOS 10 – Info.plist

You can also request for access programmatically, which I prefer because in most cases you need to know if you took the access or not. Swift 4 update: //Camera AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in if response { //access granted } else { } } //Photos let photos = PHPhotoLibrary.authorizationStatus() if photos == .notDetermined { PHPhotoLibrary.requestAuthorization({status … Read more

WKWebView not loading local files under iOS 8

They finally solved the bug! Now we can use -[WKWebView loadFileURL:allowingReadAccessToURL:]. Apparently the fix was worth some seconds in WWDC 2015 video 504 Introducing Safari View Controller For iOS8 ~ iOS10 (Swift 3) As Dan Fabulish’s answer states this is a bug of WKWebView which apparently is not being solved any time soon and as … Read more

Migrating from UIWebView to WKWebView

UIWebView => WKWebView Equivalent UIWebViewDelegate => WKNavigationDelegate delegate => navigationDelegate didFailLoadWithError => didFailNavigation webViewDidFinishLoad => didFinishNavigation webViewDidStartLoad => didStartProvisionalNavigation shouldStartLoadWithRequest => decidePolicyForNavigationAction About shouldStartLoadWithRequest you can write: func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { print(“webView:\(webView) decidePolicyForNavigationAction:\(navigationAction) decisionHandler:\(decisionHandler)”) switch navigationAction.navigationType { case .linkActivated: if navigationAction.targetFrame == nil { self.webView?.loadRequest(navigationAction.request) } … Read more

Why is WKWebView not opening links with target=”_blank”?

My solution is to cancel the navigation and load the request with loadRequest: again. This will be come the similar behavior like UIWebView which always open new window in the current frame. Implement the WKUIDelegate delegate and set it to _webview.uiDelegate. Then implement: – (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { if … Read more

Can I set the cookies to be used by a WKWebView?

Edit for iOS 11+ only Use WKHTTPCookieStore: let cookie = HTTPCookie(properties: [ .domain: “example.com”, .path: “https://stackoverflow.com/”, .name: “MyCookieName”, .value: “MyCookieValue”, .secure: “TRUE”, .expires: NSDate(timeIntervalSinceNow: 31556926) ])! webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) Since you are pulling them over from HTTPCookeStorage, you can do this: let cookies = HTTPCookieStorage.shared.cookies ?? [] for cookie in cookies { webView.configuration.websiteDataStore.httpCookieStore.setCookie(cookie) } Old answer for … Read more

Xcode 9 GM – WKWebView NSCoding support was broken in previous versions

The error is correct behavior, and not a bug in Xcode 9. Although WKWebView was introduced in iOS 8, there was a bug in -[WKWebView initWithCoder:] that was only fixed in iOS 11, which always crashed at runtime and thus prevented configuring one within Interface Builder. https://bugs.webkit.org/show_bug.cgi?id=137160 Rather than allow developers to build something in … Read more