WebView is not loading webpage iOS 10 & Swift 3 - ios

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.

Related

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)!)

URL does not load on webview

So I have this link
https://api1341.mr009.com/game/ptLaunchGame?agent=mobile&gameCode=art&gameType=8&sig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMTc4NDQsImxvZ2luTmFtZSI6ImRldnRlc3Q0NyIsImlhdCI6MTUzMTM5MTQ2OH0.0Ao0O9dPMWvWAHeYE1j4w5f2uLN7C32oMmVXbvTI1qQ
Which I try to run on a webview, but it doesn't work.
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: urlString)
let request = URLRequest(url: url!)
webView.loadRequest(request)
}
It only works when I launch the link outside the app, such as safari browser.
Oh by the way, I can only use Webview as a requirement. No WebKitView.
It's caused by this line
webView.loadHTMLString(urlString, baseURL: nil)
That function is supposed to be used to load a local .html file, not a website from an URL. What you're doing is beginning to load a request using
webView.loadRequest(request)
and then immediately cancel it, by attempting to load a local .html file using
webView.loadHTMLString(urlString, baseURL: nil)
which obviously fails, because that's an URL, not a .html file.
Just remove
webView.loadHTMLString(urlString, baseURL: nil)
Call delegate of webview equal to self also
webView.delegate = self
self.webView.loadRequest(URLRequest(url: URL(string: self.link)!))

iOS 9 UIWebView Crash When Loading

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)

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