usar sim recibir poner pantalla mac llamar llamadas inicio hacer gratis funciona facetime directo desde crear contacto con como chip acceso ios swift phone-number phone-call

ios - sim - facetime es gratis



Llamar a un número de teléfono rápidamente (20)

Estoy tratando de llamar a un número que no usa números específicos, sino un número que se llama en una variable o al menos decirle que levante el número en su teléfono. Este número al que se llama en una variable es un número que recuperé usando un analizador sintáctico o tomando de un sitio web sql. Hice un botón tratando de llamar al número de teléfono almacenado en la variable con una función, pero fue en vano. Cualquier cosa ayudará, gracias!

func callSellerPressed (sender: UIButton!){ //(This is calls a specific number)UIApplication.sharedApplication().openURL(NSURL(string: "tel://######")!) // This is the code I''m using but its not working UIApplication.sharedApplication().openURL(NSURL(scheme: NSString(), host: "tel://", path: busPhone)!) }


Para Swift 4.2 y superior

if let phoneCallURL = URL(string: "tel:///(01234567)"), UIApplication.shared.canOpenURL(phoneCallURL) { UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil) }


Aquí hay una forma alternativa de reducir un número de teléfono a componentes válidos utilizando un Scanner ...

let number = "+123 456-7890" let scanner = Scanner(string: number) let validCharacters = CharacterSet.decimalDigits let startCharacters = validCharacters.union(CharacterSet(charactersIn: "+#")) var digits: NSString? var validNumber = "" while !scanner.isAtEnd { if scanner.scanLocation == 0 { scanner.scanCharacters(from: startCharacters, into: &digits) } else { scanner.scanCharacters(from: validCharacters, into: &digits) } scanner.scanUpToCharacters(from: validCharacters, into: nil) if let digits = digits as? String { validNumber.append(digits) } } print(validNumber) // +1234567890


Bien, obtuve ayuda y lo descubrí. También puse un pequeño sistema de alerta en caso de que el número de teléfono no sea válido. Mi problema era que lo estaba llamando bien, pero el número tenía espacios y caracteres no deseados como ("123 456-7890"). La aplicación UIA solo funciona o acepta si su número es ("1234567890"). Básicamente, elimina el espacio y los caracteres no válidos creando una nueva variable para extraer solo los números. Luego llama a esos números con la aplicación UIA.

var url:NSURL = NSURL(string: "telprompt://1234567891")! UIApplication.sharedApplication().openURL(url)


En Swift 3,

if let url = URL(string:"tel:///(phoneNumber)"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.openURL(url) }


Esta es una actualización de la respuesta de @ Tom usando Swift 2.0 Nota : esta es toda la clase de CallComposer que estoy usando.

class CallComposer: NSObject { var editedPhoneNumber = "" func call(phoneNumber: String) -> Bool { if phoneNumber != "" { for i in number.characters { switch (i){ case "0","1","2","3","4","5","6","7","8","9" : editedPhoneNumber = editedPhoneNumber + String(i) default : print("Removed invalid character.") } } let phone = "tel://" + editedPhoneNumber let url = NSURL(string: phone) if let url = url { UIApplication.sharedApplication().openURL(url) } else { print("There was an error") } } else { return false } return true } }


Estoy usando este método en mi aplicación y funciona bien. Espero que esto también te pueda ayudar.

func makeCall(phone: String) { let formatedNumber = phone.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet).joinWithSeparator("") let phoneUrl = "tel:///(formatedNumber)" let url:NSURL = NSURL(string: phoneUrl)! UIApplication.sharedApplication().openURL(url) }


Estoy usando la solución swift 3 con validación de números

var validPhoneNumber = "" phoneNumber.characters.forEach {(character) in switch character { case "0"..."9": validPhoneNumber.characters.append(character) default: break } } if UIApplication.shared.canOpenURL(URL(string: "tel:///(validNumber)")!){ UIApplication.shared.openURL(URL(string: "tel:///(validNumber)")!) }


Las respuestas anteriores son parcialmente correctas, pero con "tel: //" solo hay un problema. Una vez finalizada la llamada, volverá a la pantalla de inicio, no a nuestra aplicación. Así que mejor usar "telprompt: //", volverá a la aplicación.

func callSellerPressed (sender: UIButton!){ var newPhone = "" for (var i = 0; i < countElements(busPhone); i++){ var current:Int = i switch (busPhone[i]){ case "0","1","2","3","4","5","6","7","8","9" : newPhone = newPhone + String(busPhone[i]) default : println("Removed invalid character.") } } if (busPhone.utf16Count > 1){ UIApplication.sharedApplication().openURL(NSURL(string: "tel://" + newPhone)!) } else{ let alert = UIAlertView() alert.title = "Sorry!" alert.message = "Phone number is not available for this business" alert.addButtonWithTitle("Ok") alert.show() } }


Para un enfoque Swift 3.1 y compatible con versiones anteriores, haga esto:

@IBAction func phoneNumberButtonTouched(_ sender: Any) { if let number = place?.phoneNumber { makeCall(phoneNumber: number) } } func makeCall(phoneNumber: String) { let formattedNumber = phoneNumber.components(separatedBy: NSCharacterSet.decimalDigits.inverted).joined(separator: "") let phoneUrl = "tel:///(formattedNumber)" let url:NSURL = NSURL(string: phoneUrl)! if #available(iOS 10, *) { UIApplication.shared.open(url as URL, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url as URL) } }


Sólo inténtalo:

if let url = NSURL(string: "tel:///(busPhone)") where UIApplication.sharedApplication().canOpenURL(url) { UIApplication.sharedApplication().openURL(url) }

asumiendo que el número de teléfono está en busPhone .

El init(string:) NSURL init(string:) devuelve un Opcional, por lo tanto, al usar if let NSURL que url sea ​​un NSURL (y no un NSURL? Como lo devuelve el init ).

Para Swift 3:

if let url = URL(string: "tel:///(busPhone)"), UIApplication.shared.canOpenURL(url) { if #available(iOS 10, *) { UIApplication.shared.open(url) } else { UIApplication.shared.openURL(url) } }

Necesitamos verificar si estamos en iOS 10 o posterior porque:

''openURL'' quedó en desuso en iOS 10.0


Si su número de teléfono contiene espacios, ¡elimínelos primero! Luego puede usar la solución de la respuesta aceptada .

let numbersOnly = busPhone.replacingOccurrences(of: " ", with: "") if let url = URL(string: "tel:///(numbersOnly)"), UIApplication.shared.canOpenURL(url) { if #available(iOS 10, *) { UIApplication.shared.open(url) } else { UIApplication.shared.openURL(url) } }


Solución Swift 3.0:

let formatedNumber = phone.components(separatedBy: NSCharacterSet.decimalDigits.inverted).joined(separator: "") print("calling /(formatedNumber)") let phoneUrl = "tel:///(formatedNumber)" let url:URL = URL(string: phoneUrl)! UIApplication.shared.openURL(url)


Swift 3, iOS 10

func call(phoneNumber:String) { let cleanPhoneNumber = phoneNumber.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "") let urlString:String = "tel:///(cleanPhoneNumber)" if let phoneCallURL = URL(string: urlString) { if (UIApplication.shared.canOpenURL(phoneCallURL)) { UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil) } } }


Swift 3.0 y iOS 10 o anterior

func phone(phoneNum: String) { if let url = URL(string: "tel:///(phoneNum)") { if #available(iOS 10, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url as URL) } } }


Swift 4,

private func callNumber(phoneNumber:String) { if let phoneCallURL = URL(string: "telprompt:///(phoneNumber)") { let application:UIApplication = UIApplication.shared if (application.canOpenURL(phoneCallURL)) { if #available(iOS 10.0, *) { application.open(phoneCallURL, options: [:], completionHandler: nil) } else { // Fallback on earlier versions application.openURL(phoneCallURL as URL) } } } }


Una solución autónoma en iOS 10, Swift 3 :

private func callNumber(phoneNumber:String) { if let phoneCallURL = URL(string: "tel:///(phoneNumber)") { let application:UIApplication = UIApplication.shared if (application.canOpenURL(phoneCallURL)) { application.open(phoneCallURL, options: [:], completionHandler: nil) } } }

Debería poder usar callNumber("7178881234") para hacer una llamada.


openURL () ha quedado en desuso en iOS 10. Aquí está la nueva sintaxis:

if let url = URL(string: "tel:///(busPhone)") { UIApplication.shared.open(url, options: [:], completionHandler: nil) }


Para swift 3.0

if let url = URL(string: "tel:///(number)"), UIApplication.shared.canOpenURL(url) { if #available(iOS 10, *) { UIApplication.shared.open(url) } else { UIApplication.shared.openURL(url) } } else { print("Your device doesn''t support this feature.") }



let formatedNumber = phone.components(separatedBy: NSCharacterSet.decimalDigits.inverted).joined(separator: "") print("calling /(formatedNumber)") let phoneUrl = "tel:///(formatedNumber)" let url:URL = URL(string: phoneUrl)! UIApplication.shared.openURL(url)