Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting components of NSURL as phone number

Tags:

ios

swift

nsurl

I have an NSURL being returned to me as something like

tel:555-555-5555

I can recognize it as a telephone by identifying the NSURL's scheme as "tel" using

let url = NSURL(string: "tel:555-555-5555")
if url.scheme == "tel" {
    // it's a telephone number
}

But I can't find a command to get the actual phone number component. The phone numbers can come back much more messy than the example I gave, so I thought it would be much safer to ask if there was a way to get the phone number component directly instead of saving as string and clipping out the scheme.

like image 348
Tamarisk Avatar asked Oct 23 '25 15:10

Tamarisk


1 Answers

Use resourceSpecifier:

let url = NSURL(string: "tel:555-555-5555")!
if url.scheme == "tel" {
    let number = url.resourceSpecifier
}
like image 176
Code Different Avatar answered Oct 26 '25 04:10

Code Different



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!