How to make facetime call from Swift?
Asked Answered
S

2

9

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!

Starfish answered 4/8, 2014 at 23:59 Comment(1)
How did you try and write it in Swift? Let's start there rather than turning SO into a code translation service.Secor
B
14

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.

Blurb answered 25/4, 2015 at 19:14 Comment(0)
S
6

Allow me to answer my own question...

I originally used the following code

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"facetime://tel-number"]];

With the help of this question, and the Apple Facetime API docs, I determined that the proper code was :

UIApplication.sharedApplication().openURL(NSURL(string: "facetime://tel-number"))

I hope this helps anyone else in the future.

Starfish answered 5/8, 2014 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.