2012-07-18 63 views
0
NSString *phoneStr = @"tel:"; 
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone]; 
NSURL * phoneURL = [NSURL URLWithString:phoneStr]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 

此代码不工作,不开手机的应用程序,当我打印phoneURL的值总是空无法打开手机应用程序编程

这是为什么会发生什么?

THX

+0

ContactPhone是NSString的类型? – samfisher 2012-07-18 12:35:46

+0

是的,它是NSString类型 – 2012-07-18 12:36:19

+0

首先不需要输入NSURL。其次,phoneStr有没有什么价值? – Nitish 2012-07-18 12:37:06

回答

1

你错过了//电话:

NSString *phoneStr = @"tel://"; 
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone]; 
NSURL * phoneURL = [NSURL URLWithString:phoneStr]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 
+0

不工作,仍然phoneUrl值为空 – 2012-07-18 12:44:43

+0

如果我用静态字符串替换ContactPhone的值,它可以正常工作,即如此 phoneStr = [phoneStr stringByAppendingFormat:@“55555”]; 我确信contactPhone值不为空 – 2012-07-18 12:46:38

+0

做一件事。而不是self.ContactPhone只使用ContactPhone。你确定ContactPhone是NSString吗? – Nitish 2012-07-18 12:48:07

0

首先,检查self.ContactPhone不是空的,并使用@ “telprompt://”在结束通话后返回或重新启动您的应用。

NSString *phoneStr = @"telprompt://"; 
if([self.ContactPhone length]>0) 
{ 
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone]; 
NSURL * phoneURL = [NSURL URLWithString:phoneStr]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 
} 
3

你需要躲避手机串:

[NSURL URLWithString:[phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] 
相关问题