How can I to make a phone call with swift 3.0
I used the following code in Swift 3.0
UIApplication.shared.open(openURL, options: [:], completionHandler: nil)
But its not running on xCode 8.1
How can I make a call in swift 3.0?
Use this:
guard let url = URL(string: "telprompt://" + number) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)
For popup use telprompt://\(number) and for direct call use tel://\(number)
Related
I can make a phone call with this code:
if let url = URL(string: "telprompt://\(number)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Now I want to make a phone call with hidden phone number, so I would add #31# but then url is not, and the canOpenURL function is not even called.
if let url = URL(string: "telprompt://#31#\(number)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
tel:// scheme responds the same, and I don't want to go in the system settings and change it there, as it would hide my number on every call I make.
Any idea?
Xcode 11.5 - macOS Catalina - Swift 5
Have you tried url-encoding the # ?
"telprompt://%2331%23\(number)"
tazah://posts?postID=10
I need to make this a clickable link without using http
You can open urls using this code
UIApplication.shared.open(url, options: [:], completionHandler: nil)
So in your case:
if let url = URL(string: "tazah://posts?postID=10") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
Just add in you info.plist int the URL types scheme.
https://jayeshkawli.ghost.io/ios-custom-url-schemes/
Inside an iOS app of mine I want to set a button which is going to allow me to view a movie in the iTunes app.
Is that possible?
If yes, how can I do it?
Swift 3, iOS 10 and above.
if let url = URL(string: "itms://itunes.apple.com/"),
UIApplication.shared.canOpenURL(url){
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Hello I've button action for call number , but when I used it don't call and nothing shows.
My codes under below.
#IBAction func callPhone(sender: AnyObject) {
UIApplication.shared().canOpenURL((NSURL(string: "tel://1234567890")! as URL))
}
Thank You !
Proper Swift 3.0 Code
if let url = URL(string: "tel://\(phoneNumber)") {
UIApplication.shared().open(url, options: [:], completionHandler: nil)
}
In Swift 3.0 NSURL have changed to URL. And sharedApplciation changed to shared. Also OpenURL changed to open, they have added a bunch other parameters to the openmethod, you can pass empty dictionary in options and nil in the completionHandler.
Please try following code it's use to solve your problem.
if let url = NSURL(string: "tel://\(1234567890)") {
UIApplication.sharedApplication().openURL(url)
}
Try this answer.
#IBAction func callPhone(sender: AnyObject) {
if let url = NSURL(string: "tel://9069118117") {
UIApplication.sharedApplication().openURL(url)
}
}
please note that:
tel:// try to call direct the phone number;
telprompt:// shows you an alert to confirm call
as of iOS 10 openUrl is deprecated;
#available(iOS, introduced: 2.0, deprecated: 10.0, message: "Please use openURL:options:completionHandler: instead")
open func openURL(_ url: URL) -> Bool
so i advice to use this code block to support also iOS < 9:
if #available(iOS 10, *) {
UIApplication.shared.open(yourURL)
// if you need completionHandler:
//UIApplication.shared.open(yourURL, completionHandler: { (aBool) in })
// if you need options too:
//UIApplication.shared.open(yourURL, options: [:], completionHandler: { (aBool) in })
} else {
UIApplication.shared.openURL(number)
}
Latest Xcode , Latest Swift working codes.
use telprompt:// not tel
let myphone = "+134345345345"
if let phone = URL(string:"telprompt://\(myphone)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}
I created a button to make a call from app:
#IBAction func callButton(sender: AnyObject) {
if (PhoneNumber != ""){
UIApplication.sharedApplication().openURL(NSURL(string: "telprompt://\(PhoneNumber)")!)
}
}
and it works perfectly fine. Strange thing happens when I want to open a web page. I use nearly exactly same code
#IBAction func openWeb(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: "www.google.com")!)
}
But this time button doesn't react and nothing happens. Wherever I was looking for some information about opening web pages in safari from the app, the code was written exactly this way. Do you have any idea where the problem is?
Thanks in advance!
missing url scheme
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
Swift 4, safely unwrapped optional, check if canOpenURL
if let url = URL(string: "https://www.google.com"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
Swift 3 Version
UIApplication.shared.openURL(NSURL(string: "http://google.com")! as URL)
Updated Swift 3.0 version as of iOS 10
let googleURL = NSURL(string: "www.google.com")! as URL
UIApplication.shared.open(googleURL, options: [:], completionHandler: nil)
Swift 4.2.1, iOS 10 and higher
UIApplication.shared.open(URL(string: "https://google.com")!, options: [:], completionHandler: nil)