Iphone Can';t以编程方式打开电话应用程序
这段代码不工作,也没有打开电话应用程序,当我打印phoneURL的值时,它总是空的 为什么会发生这种情况Iphone Can';t以编程方式打开电话应用程序,iphone,ios,Iphone,Ios,这段代码不工作,也没有打开电话应用程序,当我打印phoneURL的值时,它总是空的 为什么会发生这种情况 Thx您错过了/之后的电话: NSString *phoneStr = @"tel:"; phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone]; NSURL * phoneURL = [NSURL URLWithString:phoneStr]; [[UIApplication sharedAp
Thx您错过了/之后的电话:
NSString *phoneStr = @"tel:";
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
你错过了/之后的电话:
NSString *phoneStr = @"tel:";
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
首先,检查self.ContactPhone是否为空,并在结束通话后使用@“telprompt://”返回或重新启动应用程序
NSString *phoneStr = @"tel://";
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
首先,检查self.ContactPhone是否为空,并在结束通话后使用@“telprompt://”返回或重新启动应用程序
NSString *phoneStr = @"tel://";
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
您需要转义电话字符串:
NSString *phoneStr = @"telprompt://";
if([self.ContactPhone length]>0)
{
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
}
您需要转义电话字符串:
NSString *phoneStr = @"telprompt://";
if([self.ContactPhone length]>0)
{
phoneStr = [phoneStr stringByAppendingFormat:@"%@" , self.ContactPhone];
NSURL * phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
}
这里是Swift 4.1的代码
[NSURL URLWithString:[phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
这里是Swift 4.1的代码
[NSURL URLWithString:[phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
ContactPhone是NSString类型?首先,不需要输入cast NSURL。其次,phoneStr中是否有任何值?是的,phoneStr中有一个值,我打印它并获得正确的值。您可以记录您的
self.ContactPhone
并在任何情况下进行检查如果您在ContactPhone中有值,NSURL将正确初始化。使用ur代码。ContactPhone是NSString类型?首先,无需键入cast NSURL。其次,phoneStr中是否有任何值?是的,phoneStr中有一个值,我打印它并获得正确的值。您可以记录您的self.ContactPhone
并在任何情况下进行检查如果您在ContactPhone中有值,NSURL将正确初始化。使用ur代码。如果我用静态字符串替换ContactPhone的值,它可以正常工作,即类似于phoneStr=[PhoneStringByAppendingFormat:@“55555”];而且我确信contactPhone的值不是空的,只做一件事。用ContactPhone代替self.ContactPhone。你确定ContactPhone是一个NSString吗?是的,我也删除了self,但phoneURL仍然为空。请写入phoneStr的值。如果我用静态字符串替换ContactPhone的值,它可以正常工作,即像这样phoneStr=[PhoneStringByAppendingFormat:@“55555”];而且我确信contactPhone的值不是空的,只做一件事。用ContactPhone代替self.ContactPhone。你确定ContactPhone是NSString吗?是的,我也删除了self,但phoneURL仍然为空。请写下phoneStr的值。