来自Xcode中的Plist的超链接

时间:2013-10-19 20:59:52

标签: ios xcode search plist

点击后,我的应用程序中有一个按钮,可以将您带到存储在plist中的商家网站。我可以使用按钮来使用此代码:

 -(IBAction)search:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}

现在我如何操纵此代码从已经建立的plist中调用网站。

2 个答案:

答案 0 :(得分:2)

从p列表中获取链接字符串。

NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]];
NSString * urlString = dictionary[@"TheKeyPath"]; // theKeyPath referring to the key that you assigned to the url string in the p-list

然后非常简单......

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

答案 1 :(得分:0)

我这样写了但按钮似乎什么都没做,我写了一个NSLog,然后单击按钮但没有发送到safari。

-(IBAction)search:(id)sender{
    NSString *searchsite = [resultDic objectForKey:@"Search"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:searchsite]];
}

令人困惑的是我有一个这样写的调用函数,它运行得很好。

-(IBAction)callPhone:(id)sender {

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