Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Need to make a button that will call a number on an iPhone using "Call".

Hi everyone, I'm trying to make a button in my app that will call the number displayed on the button. For example, if the button title is "222-222-2222" the call function should be brought up and the number should be dialled and once the call is over, I'd also like my app to reopen. I've scoured the rest of the internet and the Apple Documentation but haven't found anything very helpful. I'm doing my code in Swift and any help would be appreciated.

1 Answer

Have you tried the following? UIApplication.sharedApplication().openURL(NSURL(string: "tel://222-222-2222")) check the docs for Phone links. You will treat the number as any other link.

Thanks a lot, that worked perfectly.