Explore WKWebView additions

RSS for tag

Discuss the WWDC21 session Explore WKWebView additions.

View Session

Posts under wwdc21-10032 tag

68 Posts
Sort by:
Post not yet marked as solved
3 Replies
267 Views
I know this question is asked many times over here but I have tried all the solutions but none of them helped me out. I am getting error in this line myWebView.load(URLRequest(url: url)) I am using navigation controller and segue performs programatically when the user defaults are available from below class ViewController: UIViewController { let defaults = UserDefaults.standard var username = "" var password = "" override func viewDidLoad() { super.viewDidLoad() if(defaults.bool(forKey: "isLoggedin") == true){ username = defaults.string(forKey: "username") ?? "" password = defaults.string(forKey: "password") ?? "" if(username != "" && password != ""){ self.navigationController?.pushViewController(WebViewViewController(), animated: true) } } } } Following is my webview uiViewController import WebKit class WebViewViewController: UIViewController { @IBOutlet weak var myWebView: WKWebView! let defaults = UserDefaults.standard var username = "" var password = "" override func viewDidLoad() { super.viewDidLoad() //myWebView = WKWebView() navigationController?.setNavigationBarHidden(true, animated: true) if(defaults.bool(forKey: "isLoggedin") == true){ username = defaults.string(forKey: "username") ?? "" password = defaults.string(forKey: "password") ?? "" if(username != "" && password != ""){ guard let url = URL(string: "https://google.com") else {return} myWebView.load(URLRequest(url: url)) } } } } My story board screen shot
Posted Last updated
.
Post not yet marked as solved
1 Replies
459 Views
Hello I have a webrtc-based web app that is loaded inside a WKWebView. The web app gets loaded just fine in our iOS App running WKWebView on an iPad with iOS 15.1. We are using the exact same app, built for Mac Catalyst. However, on the Mac version, the web app gets loaded but the RTCPeerConnection object is undefined.. Meaning that our web app assumes that WebRTC is not available in that browser. Isn't the native app supposed to work the exact same on iOS and MacOS? Is the Mac version of WKWebView more limited than its iOS counterpart ? Is there any resource that states exactly what is supported in WKWebview in each platform? Thanks
Posted Last updated
.
Post not yet marked as solved
0 Replies
210 Views
Hi, I wrote an app which loads a https webpage that do something like: var socket = new WebSocket('ws://localhost:31105'); I get no communication to the local running and listening app. I already tried to add some stuff to the Info.plist of the app which shows the webview: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsLocalNetworking</key> <true/> <key>NSExceptionDomains</key> <dict> <key>localhost</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> </dict> </dict> </dict> But I stil can not see any traffic. If I open the webpage in safari I can see the error that unsecure access is denied. But I can not add this stuff to a safari plist file for testing, or ... can I? It is not iOS it's macOS. Any ideas?
Posted
by ednt.
Last updated
.
Post not yet marked as solved
0 Replies
342 Views
Please i have an iOS webview app I'd like to submit to appstore. Will this be possible
Posted
by Fredabila.
Last updated
.
Post not yet marked as solved
0 Replies
219 Views
I am running a VUE JS based VoIP application on the WkWebView . When the application is in the foreground it captures audio from microphone and plays the audio to the speaker. When the app goes to background, it stops the audio capture from microphone. i) using the iOS15 method on WkWebView, microphoneCaptureState indicates that it is not active. ii) setMicrophoneCaptureState is called with .active but if I check the capture state in the completion handler, it still remains in the not active state. When the app goes to foreground it resumes the audio capture w/o any issue. Application has these background modes set: "Voice over IP", "Background processing", "Audio, Airplay, and PIP", "Remote notifications" and "Uses Bluetooth LE accessories" If the same VUE JS application is accessed from Safari browser, the audio capture works fine even in the background.
Posted
by phani.
Last updated
.
Post not yet marked as solved
0 Replies
290 Views
I have two app, one use SafariViewController ,another is WKwebview. For SafariViewController app: I already disable the prevent Cross-site in the Safari setting in my iphone. But SafariVewiController still prevent Cross-Site tracking. What's correct way to disable this prevent Cross-site function? For WKwebview app I have already add NSCrossWebsiteTrackingUsageDescription in to project info plist file. And can see the disable/enable button in Setting page. But it not allow to disable it. The button is in gray status. can't click on it.
Posted Last updated
.
Post not yet marked as solved
0 Replies
176 Views
I have a Hybrid webapp that runs on iOS and uses wkwebview. The user click on a button, selects a local file, and receives a variable with File API structure, which includes the filename (file1.zip). A call is triggered from the javascript side to the iOS (objective-c) with the name of the file. I want to open the file on iOS side using objective-c. But for that I need to know the path of the file. Incidently, I do see a print-out in iOS when selecting the file: file:///private/var/mobile/Containers/Data/Application/9CCE059F-2B96-46DD-9528-18B806CEC5E6/Documents/file1.jpg So I assume that the path of the file is: /private/var/mobile/Containers/Data/Application/9CCE059F-2B96-46DD-9528-18B806CEC5E6/Documents But, is there a proper / methodical way to get the file path similar to the filename? Thanks
Posted
by avnerm.
Last updated
.
Post not yet marked as solved
0 Replies
258 Views
I am integrating(SAML & OIDC) for authentication in Cordova iOS project using Cordova inapp browser plugin. This plugin internally uses WKWebView. After successful loggedIn, The WKWebview gets close automatically. If the user open again the WKWebview , it shows the login page since it does not maintain the session / cookies / Session caches. But If minimize the WKWebview and open, it retains all the data and works as expected. If the WKWebview close and open, it considers as new instance Will it possible to retain or is this behaviour / limitation of iOS-WKWebview? Do I need to change any settings in server? I have tried with retain the WKWebView,cookies,processpool,WKWebViewConfiguration in NSUserDefaults and assigned again to WebView but the issue persists. What will be the solution for this? Kindly Guide me.
Posted
by Finder-G.
Last updated
.
Post not yet marked as solved
0 Replies
434 Views
I am using WKWebView inside my Swift App for SSO login. Now, SSO session is retained due to cookies saved. In Android there's an option to clear the cache or clear data from their settings Apps. Can I make my iOS App eligible for such a feature? I don't want to give an option inside my Application to clear the cache. is there any external option available which can be used for this inspite of Re-installing the application.
Posted
by JatinGarg.
Last updated
.
Post not yet marked as solved
0 Replies
317 Views
I need to perform SSO login using WkWebView and I am not using SFSafariViewController because the URL which I use is a normal web URL and I need to stop loading of next page as soon as I get a ID value in the URL as Query parameter. Now, When I use WKWebView I am unable to logout the previous session saved in WKWebView itself until I manually clear the cache of it. is there any way I can sync Safari and WkWebView sessions, So, if I login in WkWebView I can logout the same from Safari. I have tried using ASWebAuthenticateSession but as I said I need to stop the next page reload. HELP!!!
Posted
by JatinGarg.
Last updated
.
Post not yet marked as solved
0 Replies
163 Views
When the user entered the SMS verification code in the web page, the app crashed. This will not reproduce absolutely, it will only happen on a few phones with iOS13-14. As shown in the figure, the SMS verification code does not appear in the middle of the toolbar, but on the left. Has anyone encountered this situation? Why is it so? and then, this is the crash logs: Exception Codes: 0x00000000 at 0x0000000000000000 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSTaggedPointerString stringByReplacingCharactersInRange:withString:]: nil argument' (void std::__1::__call_once_proxy<std::__1::tuple<void (&)()> >(void*) + 15845284)
Posted Last updated
.
Post not yet marked as solved
0 Replies
256 Views
I am currently using the WKWebView to evaluate Javascript in my Swift code. This code uses the callAsyncJavaScript to evaluate Javascript. My code takes parameters from the user and then injects those parameters into the Javascript string that is evaluated by callAsyncJavaScript. This of course is an opportunity for js injection attacks that could cause unwanted js to run. I know Apple uses WebViews in their own native apps like Music. But there is nowhere I can find best practices on how to prevent js injection attacks. Anyone have experience with this? Here's a sample function I use. func createMessage(message: ARMessageDto) async -> ArweaveResult {     do {       guard self.walletStr != nil && !self.walletStr!.isEmpty else {         return Result.failure(TransactionError.General("No wallet exists for this user"))       }       let balance = try await self.arweaveQuerySvc.getBalance()       if balance < 1_000_000_000_000 {         return Result.failure(TransactionError.General("Error wallet balance is less than 1,000,000,000,000 Winston"))       }       guard case .none = message.validate() else {         return Result.failure(TransactionError.ParametersInvalid(message.validate()))       }               let respondingToTransId = message.respondingToTransId ?? ""       let result = try await self.webView!.callAsyncJavaScript("""             \(baseScript!)             const arweaveSvc = main('\(walletStr!)');             const result = await arweaveSvc.createMessage(               '\(message.msg)',               \"\(message.userName)\",               \"\(respondingToTransId)\"             );             return result;           """, contentWorld: WKContentWorld.defaultClient)       _ = await self.arweaveQuerySvc.mine()       return try getTransactionResult(result: result)     } catch {       return Result.failure(TransactionError.General("Failed to create profile"))     }   }
Posted
by dharric.
Last updated
.
Post not yet marked as solved
0 Replies
175 Views
I have implemented a mini browser using WKWebView. This implementation works with https web server with password authentication. But this fails when the two factor authentication is enabled using a client certificate. The two factor authentication using client certificate works from Chrome and Safari browser. Any idea how to implement this?
Posted Last updated
.
Post not yet marked as solved
0 Replies
205 Views
In my case, I have website (that includes 3 button shared for Line, Twitter, Facebook). Everything was working well until I check the action link clicked inside webView. My code have jumped from webView to shared links even I not click inside webView. (when it first load webView). My code: func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let urlMain = navigationAction.request.url { if urlMain.host == "line.me" { decisionHandler(WKNavigationActionPolicy.cancel) UIApplication.shared.openURL(urlMain) } decisionHandler(WKNavigationActionPolicy.allow) } Can you help me find the solution? All I want is when I first present webView, it not navigate to shared links, and it only work when I click on button shared in webView. Thanks you!
Posted
by Kikiki123.
Last updated
.
Post not yet marked as solved
0 Replies
155 Views
I am opening a url using UIapplication.open() method fonts are not scaling when I increase the size, is it even possible to increase the font
Posted
by abinguma.
Last updated
.
Post not yet marked as solved
1 Replies
504 Views
0 I followed the code snippet by @iUrii from this post: https://stackoverflow.com/a/63645453/981806. However, my app crashes and gets this error on some sites: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Completion handler passed to -[WebSource.MainViewController webView:didReceiveAuthenticationChallenge:completionHandler:] was not called' terminating with uncaught exception of type NSException (lldb) Code snippet below: func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {     var error: CFError?     if #available(iOS 12.0, *) {       DebugLog(tag: TAG, info: "WebView: didReceive challenge - ios12 or higher")       if let trust = challenge.protectionSpace.serverTrust, !SecTrustEvaluateWithError(trust, &error) {         // OK         let ok = UIAlertAction(title: "OK", style: .default) { _ in           let exceptions = SecTrustCopyExceptions(trust)           SecTrustSetExceptions(trust, exceptions)           completionHandler(.useCredential, URLCredential(trust: trust))         }         // Cancel         let cancel = UIAlertAction(title: "Cancel", style: .cancel) { _ in           completionHandler(.cancelAuthenticationChallenge, nil)         }         // Show prompt         let message = error!.localizedDescription + "\nDo you want to continue?"         let alert = UIAlertController(title: "SSL Error", message: message, preferredStyle: .alert)         alert.addAction(ok)         alert.addAction(cancel)         DispatchQueue.main.async {           self.present(alert, animated: true, completion: nil)         }       }       else {         let cred = URLCredential(trust: challenge.protectionSpace.serverTrust!)         completionHandler(.useCredential, cred)       }     } else {       DebugLog(tag: TAG, info: "WebView: didReceive challenge - fallback older versions")       let cred = URLCredential(trust: challenge.protectionSpace.serverTrust!)       completionHandler(.useCredential, cred)     }   } On some sites like badssl.com, the alert dialog is displaying fine and it was able to wait for user action from the dialog. Please help on what am I missing here. Thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
397 Views
This HTML and javascript content Make my WKWebView crash in ios15 What is wrong with this part? Attach my crash log Please help..... Swipy  2021-11-23, 3-27 PM.crash 2021-11-24 09:48:26.705150+0800 Swipy[510:18443] -[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560 2021-11-24 09:48:26.715730+0800 Swipy[510:18443] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560' *** First throw call stack: (0x181be904c 0x19a25df54 0x181cc6014 0x181b7e474 0x181b7d5b0 0x18dc24718 0x19061d2a4 0x1907ec908 0x1907ec470 0x19074e16c 0x19075b464 0x190ae205c 0x1903278e0 0x190329060 0x18dc1e074 0x18dc1f1e4 0x181c0b020 0x181c1bce0 0x181b55fe8 0x181b5b7f4 0x181b6f3b8 0x19d4ff38c 0x18450f6a8 0x18428e7f4 0x100d60108 0x101481a24) libc++abi: terminating with uncaught exception of type NSException dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560' terminating with uncaught exception of type NSException
Posted Last updated
.
Post not yet marked as solved
0 Replies
422 Views
Below IOS 15 It is normal to use WKWebView redirect But after the update IOS15 It may be that the browser blocked it and caused the crash Is there a solution for this Attach my crash log Please help..... 2021-11-24 09:48:26.705150+0800 Swipy[510:18443] -[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560 2021-11-24 09:48:26.715730+0800 Swipy[510:18443] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560' *** First throw call stack: (0x181be904c 0x19a25df54 0x181cc6014 0x181b7e474 0x181b7d5b0 0x18dc24718 0x19061d2a4 0x1907ec908 0x1907ec470 0x19074e16c 0x19075b464 0x190ae205c 0x1903278e0 0x190329060 0x18dc1e074 0x18dc1f1e4 0x181c0b020 0x181c1bce0 0x181b55fe8 0x181b5b7f4 0x181b6f3b8 0x19d4ff38c 0x18450f6a8 0x18428e7f4 0x100d60108 0x101481a24) libc++abi: terminating with uncaught exception of type NSException dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x281eb9560' terminating with uncaught exception of type NSException Swipy 2021-11-23, 3-27 PM.crash
Posted Last updated
.