iOS 9 UIWebView Crash When Loading - ios

I have an Url http://m3.jusfoun.com/app2.0/html2.0/czxfx.html?ent_id=2497283&userid=14304
I scroll web view down always when the url is not loaded completely,then it is crash on iOS 9
let url=NSURL(string: "http://m3.jusfoun.com/app2.0/html2.0/czxfx.html?ent_id=2497283&userid=14304")
let request:NSURLRequest = NSURLRequest(URL: url!)
mywebview.loadRequest(request)

Related

How to create a iOS Webview App (HTML5) with Xcode?

I'm trying to load local html5 files to Xcode to create an ios App. I tried using a template and it uses both local and web based paths to create a very nice ios app in Xcode.
I need to learn about how to create a a webview app that has normal features and can load my local html5 webapps into Xcode for compiling an ios app.
I tried the following code, and it works alright when loading a url based html5 page.
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
https://developer.apple.com/documentation/webkit/wkwebview
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https://www.apple.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}}
I need to change the URL to local file path. The above code page from apple documentation suggests that I use load(_: ) to load local html files. I'm not sure how to use this function. So, I tried code samples from alternate sources, and here's some part of the code I'm trying with for the Webview app.
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
#IBOutlet var webView: WKWebView!
//var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
guard let fileUrl = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "www-WebsiteContent") else { return; }
//let urlPath = Bundle.main.url(forResource: "input", withExtension: "txt")
if fileUrl != "" {
let url = URL(fileURLWithPath: fileUrl)
//let url = init(_: fileURLWithPath, path: "www-WebsiteContent/index.html")
webView.loadFileURL(url, allowingReadAccessTo : url)
let request = URLRequest(url: url)
webView.load(request)
}
//let myURL = URL(string:"file:///www-WebsiteContent/index.html")
//let myRequest = URLRequest(url: myURL!)
//webView.load(myRequest)
//webView.loadFileURL(URL: , webView.allowingReadAccessTo readAccessURL: URL)
}}
I'm using latest Xcode version on Macbook Air with latest Swift 5 version. There's a main storyboard with the webview object, and a viewcontroller.swift file.
The error is that when I run the project, it doesn't display the index.html file in the www-WebsiteContent folder. Maybe I wasn't able to connect the webview overlay to the viewcontroller.swift file properly.
Things I need to understand:
Can I run the above code and compile it as a complete ios app? Or would I need to edit AppDelegate or SceneDelegate files too? I've only edited the viewcontroller.swift file as a new project.
How can I resize the webview overlay to automatic width and height of the ios device? I have an html5 webapp files that I need to convert to an ios app. How can I create this webview so that it fits all the device types screen sizes? My html5 app fits perfectly when viewed in the device browser.

Playing sound pause when scrolling WKWebView

I have a simple WKWebView controller in my application that loads a local HTML file. HTML file including following code...
<audio autoplay="true" controls>
<source src="./audio/sound.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
Everything works fine, but when the user scrolls the webview, the sound stops, when the scrolling ends, the playback continues.
override func viewDidLoad() {
super.viewDidLoad()
let htmlPath = Bundle.main.path(forResource: "main", ofType: "htm", inDirectory: "level")
let url = URL(fileURLWithPath: htmlPath!)
let request = URLRequest(url: url)
webView.load(request)
}
Trying load remote file, but problem is same:
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.computerhope.com/jargon/h/html-audio-tag.htm")!
let request = URLRequest(url: url)
webView.load(request)
}
iOS version: 12.1
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.computerhope.com/jargon/h/html-audio-tag.htm")!
myWebKit.load(URLRequest(url: url))
myWebKit.allowsBackForwardNavigationGestures = true
// Do any additional setup after loading the view.
}
I tried this code.. its working fine for me.. audio is still playing while scrolling the page
myWebKit.allowsBackForwardNavigationGestures = true
try this

Why does webkit view not connect to App Store

The following code does not work:
override func loadView() {
self.view = webView
let url = NSURL(string: "https://itunes.apple.com/gb/app/economics-a-level/id1300094663?mt=8")!
webView.load(URLRequest(url: url as URL))
}
But if instead I put https://apple.com it does work.
I am using a test device.
So how can I direct a user to my app on the App Store?
You don't need a webview to open the app store, simply do this:
let url = "itms-apps://itunes.apple.com/app/id1300094663"
UIApplication.shared.open(URL(string: url)!)

WebView is not loading webpage iOS 10 & Swift 3

I am facing this strange issue. When I use url1, webView works fine. But when I use url2, webView sometimes doesn't load anything & only blank screen is displayed.
What should I do to solve this issue?
let url1 = "https://www.apple.com"
let url2 = "https://itunes.apple.com/us/music-video/despacito-feat-daddy-yankee/id1194807248"
override func viewDidLoad()
{
super.viewDidLoad()
let url = URL(string: url2)
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}
If you are testing on simulator, & trying to open an iTunes URL in WebView, then the webpage is not loaded in webview.
If you testing on device, then the webpage for iTunes URL gets loaded in webview.
The below url
"https://itunes.apple.com/us/music-video/despacito-feat-daddy-yankee/id1194807248"
not handled by the UIWebView to load in simulator so try on device or open using UIApplication.shared.open(url!, options: [:], completionHandler: nil) mathod.

Swift Store cookie in iOS app

I'm trying to create a simple webview app of my website, I load the url, make some actions (saving cookies) without problems but, when I close and re-open my app, all cookies are destroyed.
Where is the problem?
Thanks.
super.viewDidLoad()
let urlString = "http://my.url"
let url = NSURL(string: urlString)
let request = NSMutableURLRequest(URL: url!)
webView.loadRequest(request)

Resources