Swift Store cookie in iOS app - ios

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)

Related

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 - Ephemeral Session and UIWebView

I'd like to load a web page into a UIWebView, using URLSession.
An ephemeral session, indeed, because i wouldn't like to store the session if, for example, i've a login on Twitter/FB/whatever site.
So, i've a UIWebView named webPage
#IBOutlet var webPage: UIWebView!
a UITextField, where i can write the URL
#IBOutlet var urlField: UITextField!
Next to this text field, i've a UIButton, that implements this action
#IBAction func sendUrl(_ sender: Any) {
let stringUrl = urlField.text
let url = URL (string: stringUrl!)
openPageWithSession(url: url!)
}
and the function openPageWithSession, where i use the ephemeral session
func openPageWithSession(url: URL){
let request = URLRequest(url: url)
let ephemeralConfiguration = URLSessionConfiguration.ephemeral
let ephemeralSession = URLSession(configuration: ephemeralConfiguration)
let task = ephemeralSession.dataTask(with: request) { (data, response, error) in
if error == nil {
self.webPage.loadRequest(request)
} else {
print("ERROR: \(error)")
}
}
task.resume()
}
The loading of the web page it's ok. But if i've a login on Twitter and after that i kill the app, if i reopen the app and navigate Twitter again, i'm already logged in!
Why? The ephemeral session is not invalidate after a kill?
From the comments above.
Instead of self.webPage.loadRequest(request), you should use:
self.webView.load(data, mimeType: "text/html", textEncodingName: "", baseURL: url).
This way you'll be using the ephemeral session you created. Otherwise you're just loading the web view normally, without the ephemeral session at all.

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.

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)

Resources