How to make a phone call from Apple watch?

2019-07-07 08:27发布

问题:

Is there a way to make phone calls from WatchKit extension?

Below is my code.

NSExtensionContext *ctx = [[NSExtensionContext alloc] init];
NSString *cleanedString = [[@"1234567890" componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];
[ctx openURL:telURL completionHandler:^(BOOL success) {
    NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];