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)!))
Related
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
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)!)
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.
In my iphone app I've got to load a mobile website to a webview (that contain in a separate viewcontroller). All good and working fine.
I need to exit from webview when reach to specific set of URL's. The problem is some of these url's does not exis and therefore page does not finish load (Even with page not found error message to detect current url. Just hangs)
Would like to know if I have to enable any setting in the webView to allow load pages that does not really exist (With page not found error).
OR
Is this possible to know which URL going to load next in
func webViewDidStartLoad(webView: UIWebView)
override func viewDidLoad()
{
super.viewDidLoad()
myWebview.delegate = self
var returnUrlAppendedPaymmentLink = "www.existing_url.com"
let requestURL = NSURL(string: returnUrlAppendedPaymmentLink)
let request = NSURLRequest(URL: requestURL!)
myWebview.loadRequest(request)
}
func webViewDidFinishLoad(webView: UIWebView)
{
var currentUrl = webView.request?.URL?.absoluteString ?? ""
if (currentUrl == "www.special_url.com")
{
self.navigationController?.popViewControllerAnimated(true)
}
}
To intercept specific URLs, use the shouldStartLoadWithRequest delegate method of UIWebView.
You can check the URL of the request in this method to see if this is your "special" URL, do your handling for this case and return false so the web-view won't load it.
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)