我试图在Apple Watch上向用户显示不同的电话号码,并且他点击一个电话号码警报应该出现。我会像这样做,但警报只是在没有通话动作的情况下被解雇:
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:0];
WKExtension *myExt = [WKExtension sharedExtension];
for (NSString *phone in arr) {
NSString *tel = [NSString stringWithFormat:@"tel:%@",phone];
WKAlertAction *act = [WKAlertAction actionWithTitle:tel style:WKAlertActionStyleDefault handler:^(void){
[myExt openSystemURL:[NSURL URLWithString:phone1]];
}];
[tempArray addObject:act];
}
NSString *titleMessage = @"Call";
NSString *textMessage = @"Please select the number you want to call.";
NSString *cancel = @"Cancel";
WKAlertAction *act = [WKAlertAction actionWithTitle:cancel style:WKAlertActionStyleDestructive handler:^(void){
}];
[tempArray addObject:act];
[self presentAlertControllerWithTitle:titleMessage message:textMessage preferredStyle:WKAlertControllerStyleAlert actions:tempArray];
按钮按预期显示,并且还使用正确的电话号码调用处理程序。但它没有openSystemURL。有人知道为什么以及如何解决?谢谢!
答案 0 :(得分:0)
我想你忘了添加" tel"方案,使用以下代码:
[WKAlertAction actionWithTitle:@"tel" style:WKAlertActionStyleDefault handler:^(void){
[[WKExtension sharedExtension]openSystemURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"YOUR NUMBER"]]];
}];