How to make facetime call from Swift?

rocket101 picture rocket101 · Aug 5, 2014 · Viewed 9.6k times · Source

I am developing an app in Swift for iPad that makes use of facetime.

I know Apple introduced App projection (described about 3/4 of way down page) (where one app can "project" itsself into another) in iOS 8. Is facetime capable of this, and if so, how do I access this functionality in swift?

If not, how does one use facetime from an app programatically otherwise? I found this question about the Swift API that explained how to do it in objective C. How do I adapt that code to work in swift? When I use it as written, I get the error "Expected ; seperator"

Barring the above two, is there any other or better ways to program facetime functionality for a swift app?

Thanks!

Answer

Zorayr picture Zorayr · Apr 25, 2015

A bit more self-contained solution in Swift:

private func facetime(phoneNumber:String) {
  if let facetimeURL:NSURL = NSURL(string: "facetime://\(phoneNumber)") {
    let application:UIApplication = UIApplication.sharedApplication()
    if (application.canOpenURL(facetimeURL)) {
      application.openURL(facetimeURL);
    }
  }
}

Now, you should be able to use facetime("7178881234") to make a facetime call.