ios - 来自 plist iOS 的电话

标签 ios objective-c plist

我如何操作这段代码让它从 plist 中提取电话号码?

-(IBAction)callPhone:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:2135554321"]];
}

最佳答案

你应该将你的 plist 添加到你的项目中(如果它在你的包中)(例如,如果它是一个字典):

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"clubs" ofType:@"plist"];
    telsDictionary = [NSDictionary dictionaryWithContentsOfFile:filePath];

例如,您的 plist 又是一个 NSDictionary:

{"Mike","2135554321" "Deniel","2135554322" "Sandra","2135554323"}

如果你想调用丹尼尔:

 -(IBAction)callPhone:(id)sender {

    NSString* yourActualNumber = [NSString stringWithFormat:@"tel:%@",telsDictionary[@"Deniel"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:yourActualNumber]];
}

关于ios - 来自 plist iOS 的电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19078308/

相关文章:

ios - SecondViewController 的prepareForSegue() 和 viewDidLoad()

ios - UINavigationBar 和 UISearchBar 之间的小差距

iphone - dictionaryWithContentsOfFile 从我的属性列表文件中返回 nil

ios - 调用 plist 的子项

arrays - 如何获取项目中的plist文件列表

iOS 6 MapKit VoiceOver 在 Pins 之前读取 POI

iOS:检测附近的应用用户

ios - 通过在搜索栏 SKMAPS 中搜索名称来提供目的地建议

objective-c - 了解 Objective-C 抛出调用堆栈

ios - Objective-C 中的自定义构造函数