If I use the email address "appname.app#company.co.za" then it doesn't work but if I try appname#company.co.za then it works.
I've tried this from How to open mail app from Swift
let url = NSURL(string: "appname.app#company.co.za")
UIApplication.sharedApplication().openURL(url!)
and this
let url = NSURL(string: "appname.app#company.co.za".stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
UIApplication.sharedApplication().openURL(url!)
Related
When the user taps on a button i want to check if they have opera crypto browser installed. If they have it installed already then i want to open the url in opera crypto browser otherwise they will be redirected to app store to install the app.
The only problem with this code is that it will just open the opera crypto browser app instead of opening and loading the url that i have given. Everything else works fine. Is there anything i am doing wrong in the url or code?
let appScheme = "\("cryptobrowser")://app"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL){
guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
}else{
guard let url = URL(string: "https://apps.apple.com/pk/app/opera-crypto-browser/id1604311726") else {return}
UIApplication.shared.open(url)
}
So basically what i was doing wrong was that in my if condition where i checked to see if user has cryptobrowser installed and then i converted my url string to URL and opened it using UIApplication.shared.open() function. My URL was wrong.
I had to change my URL slightly from:
guard let url = URL(string: "cryptobrowser://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
to:
guard let url = URL(string: "cryptobrowser://open-url?url=https://reizor.com/backup8march/test2.php?token=10000000000000000000") else {return}
UIApplication.shared.open(url)
Basically adding "open-url?url=https://" after the "cryptobrowser" which is the name of browser i want the link to load in. Because apparently, to open URl in some browsers you just have to write "browserName://yourUrl" and it would open but in most case you have to include "https://" in your URL after writing the name of browser
I am calling API wih 'Alamofire'. In my response I get one weblink. I store that weblink in to one variable. Now I want to store that weblink into the local database. so I use 'userdefaults'. But when I retrive that weblink into the other 'viewcontroller' at that time my weblink changed and web page didnot open.
let weblink = datastring["Web_Link"] as! String
UserDefaults.standard.set(weblink, forKey: "Link")
for these I use this
UserDefaults.standard.set(url: URL?, forKey: String)
and in another 'viewcontroller'
let url = UserDefaults.standard.url(forKey: "Link")
for these I used
let url = UserDefaults.standard.url(forKey: String)
and my other code is
let request = URLRequest.init(url: url!)
self.webview.load(request)
my url example is "https://example.com/"
but when I retrive at that time url is
'https:/example.com'
so my webpage cannot open. I am using wkwebview.
You store the url as string so retrieve it like this.
let url = UserDefaults.standard.string(forKey: "Link")
It looks like you are storing String value in user defaults and trying to get URL from UserDefaults. So Please try as like below.
let weblink = datastring["Web_Link"] as! String
if let url = URL(string: weblink){
UserDefaults.standard.set(url, forKey: "Link")
}
I don't want to write the link " https://stackoverflow.com/questions/ask" as shown in this line. I want url to receive the last copied URL from clipboard, what should I add?
let url = URL(string: "https://stackoverflow.com/questions/ask")
Copy
let url = URL(string: "https://stackoverflow.com/questions/ask")
UIPasteboard.general.string = url
Paste
if let url = UIPasteboard.general.string {
url = url
}
I'm trying to load an image stored in a FTP server on a webview. The problem is that using
let url = "ftp://example.com/images/image1.jpg"
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.loadRequest(request)
only shows a white screen because the FTP server asks for a username and password to grant access. So my question is: how can I authenticate myself so the image from the ftp url loads in the webview?
You can build the URL using this mask.
ftp://username:password#hostname/
let login = "LoginName"
let password = "Password"
let ftpServer = "ftp.server.com"
let fileName = "example.txt"
let ftpUrl = NSURL(string: "ftp://\(login):\(password)#\(ftpServer):21/\(fileName)")
I updated to iOS 8.1 and updated my xcode but now something is broken on with my webview.
I used this part of code:
let stream = "http://stream.hive365.co.uk:8088/live"
let url = NSURL(string: stream)
let request = NSURLRequest(URL: url)
webplayer.loadRequest(request)
xcode gives a error about the let request
value of optional type NSURL? not unwrapped; did you mean to use! or ?
I'm new with iOS swift development and can't get the error away...
any help would be appreciated!
NSURL returns an optional so you need to check if it is nil
let stream = "http://stream.hive365.co.uk:8088/live"
if let url = NSURL(string: stream) {
let request = NSURLRequest(URL: url)
webplayer.loadRequest(request)
}
change
let url = NSURL(string: stream)
to
let url = NSURL(string: stream)?
or
let url : NSURL = NSURL(string: stream) as NSURL