我如何操作这段代码让它从 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/