Explore WKWebView additions

RSS for tag

Discuss the WWDC21 session Explore WKWebView additions.

Posts under wwdc21-10032 tag

73 Posts

Post

Replies

Boosts

Views

Activity

Webapp fails in iOS when using revokeObjectURL
I have a web app that loads images from a zip file, and displays them successively. The zip file can store many images. To prevent from running out of memory, the memory is managed, by cleaning the memory from previous images before showing the next image. This is done by: setting the buffer to null. revoking the object url and setting the url to null. This approach works well on various OSs such as Windows, Linux, and MacOS. But on iOS it fails. In the example, a set of images from a zip file is displayed in a loop, to mimic a zip file with many images. Setting the variable doDebugMemoryLeakOn_iOS_withRevoke to true, activates the code URL.revokeObjectURL(fileInfo.url); which causes the problem, after some time (after ~1100 images on my iPad Pro). The problem can be seen by running the program and selecting the zip file: https://cdn.jsdelivr.net/gh/avnermosh/example8_memoryLeakOn_iOS/example8_take2_3images.zip (or any other zip file with several jpeg images - the linked zip file simply contains 3 images in size of 4032x3024) At some point, the program fails with an error message: "The I/O read operation failed" This happens on various iOS devices (e.g. iPad, iPhone8) with various iOS versions (iOS 15.2, iOS 14.8.1) when played in various browsers (e.g. Safari, Chrome, Firefox) after about 1000 images. It also happens in a native iOS app that uses WKWebView. I suspect that there may be a problem with the WKWebView browser engine, which is common to all these browsers. Note: several places commented on adjusting the Safari settings e.g. GPU Process: Canvas Rendering This somewhat deferred the problem but at some point the error still occurs. After the problem occurs, there is no way to recover programatically, e.g. by retrying to read the zip file entry or skipping to the next zip entry. The only solution is to select the file again. Could this indicate a bug in WKWebView? How can this be fixed, or worked around? Thanks p.s. I also placed the question on stackoverflow that describes the problem in details and shows a link to the online example that demonstrates the problem.
1
0
1.5k
Feb ’22
Cookies issue in web view
We're using webview in our iOS app to show the web page. The website contains cookies and they need to be Accepted/Declined by the users by clicking on Accept or Decline button, Which is handled by the website. Apple asked us to either remove the cookies from web content or implement App Tracking Transparency. We added App Tracking Transparency and now the user is asked to allow or deny the tracking permission once the user allows then we show the cookie prompt in the webview and if they deny the permission we don't show the cookie prompt. To achieve this we've set one cookie when the user denies the permission - so that the cookie popup isn't shown. But our app still got rejected, below is the message by the apple review team - We noticed you collect data to track after the user selects "Ask App Not to Track" on the App Tracking Transparency permission request. Specifically, we noticed your app accesses web content you own and collects cookies for tracking after the user asked you not to track them. Next Steps To resolve this issue, please revise your app so that you do not collect data for tracking purposes if the user does not give permission for tracking. Resources Tracking is linking data collected from your app with third-party data for advertising purposes or sharing the collected data with a data broker. Learn more about tracking. See Frequently Asked Questions about the new requirements for apps that track users. Any help will be appreciated. Thanks in advance.
3
0
11k
Feb ’22
WKWebVIew Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
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
3
0
1.7k
Feb ’22
macOS webview insecure websocket to localhost
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?
0
0
761
Jan ’22
WkWebView can't capture audio in the background
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.
0
0
671
Jan ’22
How to disable Prevent Cross-Site Tracking in SafariViewController and WKWebview
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.
0
0
925
Jan ’22
How to get the path of the a selected local file in Hybrid app in iOS?
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
0
0
695
Jan ’22
WKWebview in Cookies does not retain - Cordova InApp Browser
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.
0
0
967
Jan ’22
SSO login using WKWebView with a Normal URL without callback feature
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!!!
0
0
1.1k
Dec ’21
App crashed when user input the sms code into the html input tags.
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)
0
0
502
Dec ’21
Proper Security when evaluating Javascript from within Swift code
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"))     }   }
0
0
859
Dec ’21
Certificate authentication using WKWebView
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?
0
0
465
Dec ’21
WKWebView automatically decide policy for embedded iframe url
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!
0
0
844
Dec ’21
webView:didReceiveAuthenticationChallenge:completionHandler NSException
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!
1
0
2.2k
Nov ’21
iOS15 , WKWebView crash due to HTML submit or Javascript
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
0
0
879
Nov ’21
WKWebView crash on iOS15 (browser redirect)
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
0
0
989
Nov ’21
Webapp fails in iOS when using revokeObjectURL
I have a web app that loads images from a zip file, and displays them successively. The zip file can store many images. To prevent from running out of memory, the memory is managed, by cleaning the memory from previous images before showing the next image. This is done by: setting the buffer to null. revoking the object url and setting the url to null. This approach works well on various OSs such as Windows, Linux, and MacOS. But on iOS it fails. In the example, a set of images from a zip file is displayed in a loop, to mimic a zip file with many images. Setting the variable doDebugMemoryLeakOn_iOS_withRevoke to true, activates the code URL.revokeObjectURL(fileInfo.url); which causes the problem, after some time (after ~1100 images on my iPad Pro). The problem can be seen by running the program and selecting the zip file: https://cdn.jsdelivr.net/gh/avnermosh/example8_memoryLeakOn_iOS/example8_take2_3images.zip (or any other zip file with several jpeg images - the linked zip file simply contains 3 images in size of 4032x3024) At some point, the program fails with an error message: "The I/O read operation failed" This happens on various iOS devices (e.g. iPad, iPhone8) with various iOS versions (iOS 15.2, iOS 14.8.1) when played in various browsers (e.g. Safari, Chrome, Firefox) after about 1000 images. It also happens in a native iOS app that uses WKWebView. I suspect that there may be a problem with the WKWebView browser engine, which is common to all these browsers. Note: several places commented on adjusting the Safari settings e.g. GPU Process: Canvas Rendering This somewhat deferred the problem but at some point the error still occurs. After the problem occurs, there is no way to recover programatically, e.g. by retrying to read the zip file entry or skipping to the next zip entry. The only solution is to select the file again. Could this indicate a bug in WKWebView? How can this be fixed, or worked around? Thanks p.s. I also placed the question on stackoverflow that describes the problem in details and shows a link to the online example that demonstrates the problem.
Replies
1
Boosts
0
Views
1.5k
Activity
Feb ’22
Cookies issue in web view
We're using webview in our iOS app to show the web page. The website contains cookies and they need to be Accepted/Declined by the users by clicking on Accept or Decline button, Which is handled by the website. Apple asked us to either remove the cookies from web content or implement App Tracking Transparency. We added App Tracking Transparency and now the user is asked to allow or deny the tracking permission once the user allows then we show the cookie prompt in the webview and if they deny the permission we don't show the cookie prompt. To achieve this we've set one cookie when the user denies the permission - so that the cookie popup isn't shown. But our app still got rejected, below is the message by the apple review team - We noticed you collect data to track after the user selects "Ask App Not to Track" on the App Tracking Transparency permission request. Specifically, we noticed your app accesses web content you own and collects cookies for tracking after the user asked you not to track them. Next Steps To resolve this issue, please revise your app so that you do not collect data for tracking purposes if the user does not give permission for tracking. Resources Tracking is linking data collected from your app with third-party data for advertising purposes or sharing the collected data with a data broker. Learn more about tracking. See Frequently Asked Questions about the new requirements for apps that track users. Any help will be appreciated. Thanks in advance.
Replies
3
Boosts
0
Views
11k
Activity
Feb ’22
WKWebVIew Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
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
Replies
3
Boosts
0
Views
1.7k
Activity
Feb ’22
macOS webview insecure websocket to localhost
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?
Replies
0
Boosts
0
Views
761
Activity
Jan ’22
How to include an authentication header in all requests in WKWebView
We need to include an authentication header in all requests in WKWebView, any help? Thanks.
Replies
0
Boosts
0
Views
364
Activity
Jan ’22
IOS webview app
Please i have an iOS webview app I'd like to submit to appstore. Will this be possible
Replies
1
Boosts
0
Views
905
Activity
Jan ’22
WkWebView can't capture audio in the background
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.
Replies
0
Boosts
0
Views
671
Activity
Jan ’22
iOS 15 Beta 7, WKWebView stucks (freezes with white page) when app goes to background and opened again.
On iOS 14 and lower, everything is fine.
Replies
1
Boosts
0
Views
890
Activity
Jan ’22
How to disable Prevent Cross-Site Tracking in SafariViewController and WKWebview
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.
Replies
0
Boosts
0
Views
925
Activity
Jan ’22
How to get the path of the a selected local file in Hybrid app in iOS?
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
Replies
0
Boosts
0
Views
695
Activity
Jan ’22
WKWebview in Cookies does not retain - Cordova InApp Browser
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.
Replies
0
Boosts
0
Views
967
Activity
Jan ’22
SSO login using WKWebView with a Normal URL without callback feature
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!!!
Replies
0
Boosts
0
Views
1.1k
Activity
Dec ’21
App crashed when user input the sms code into the html input tags.
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)
Replies
0
Boosts
0
Views
502
Activity
Dec ’21
Proper Security when evaluating Javascript from within Swift code
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"))     }   }
Replies
0
Boosts
0
Views
859
Activity
Dec ’21
Certificate authentication using WKWebView
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?
Replies
0
Boosts
0
Views
465
Activity
Dec ’21
WKWebView automatically decide policy for embedded iframe url
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!
Replies
0
Boosts
0
Views
844
Activity
Dec ’21
WKWebView font scaling
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
Replies
0
Boosts
0
Views
599
Activity
Dec ’21
webView:didReceiveAuthenticationChallenge:completionHandler NSException
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!
Replies
1
Boosts
0
Views
2.2k
Activity
Nov ’21
iOS15 , WKWebView crash due to HTML submit or Javascript
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
Replies
0
Boosts
0
Views
879
Activity
Nov ’21
WKWebView crash on iOS15 (browser redirect)
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
Replies
0
Boosts
0
Views
989
Activity
Nov ’21