YumYumYum YumYumYum - 1 month ago 30
iOS Question

iOS - how to write this objective-C into Swift?

How can i exactly do this in swift for iOS?

- (IBAction)skypeMe:(id)sender
{
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"skype:"]];
if(installed)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"skype:echo123?call"]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.com/apps/skype/skype"]];
}
}

Answer

Swift 3.0

Inside your button action event

let installed = UIApplication.shared.canOpenURL(URL(string: "skype:")!)

if installed {
    UIApplication.shared.openURL(URL(string: "skype:echo123?call")!)
} else {
    UIApplication.shared.openURL(URL(string: "http://itunes.com/apps/skype/skype")!)
}

Since

UIApplication.shared.openURL(URL(string: "skype:echo123?call")!)

is deprecated in iOS 10

You can use this

UIApplication.shared.open(URL(string: "skype:echo123?call")!, options: [:], completionHandler: nil)