简体   繁体   中英

Getting components of NSURL as phone number

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.

Use resourceSpecifier :

let url = NSURL(string: "tel:555-555-5555")!
if url.scheme == "tel" {
    let number = url.resourceSpecifier
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM