如何在iPhone中单击按钮打开url
我在NSString urlone中有一个url,它来自xml。但我运行应用程序,它会产生额外的错误如何在iPhone中单击按钮打开url,iphone,objective-c,Iphone,Objective C,我在NSString urlone中有一个url,它来自xml。但我运行应用程序,它会产生额外的错误 // urlone contains http://www.forasinvest.com/v2/index.php NSString*myurl=urlone; NSURL *url = [NSURL URLWithString:myurl]; [[UIApplication sharedApplication] openURL:url]; 我认为它应该工作得很好,好的,
// urlone contains http://www.forasinvest.com/v2/index.php
NSString*myurl=urlone;
NSURL *url = [NSURL URLWithString:myurl];
[[UIApplication sharedApplication] openURL:url];
我认为它应该工作得很好,好的,只是复制粘贴以下测试简单
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.forasinvest.com/v2/index.php"]];
使用iOS 11.3是迄今为止最新的代码,如果您不想看到不推荐使用的警告,请使用以下代码行:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"https://example.com"] options:@{} completionHandler:nil];
假设
urlone
是有效的,那么应该没有什么问题。你确定urlone
可以吗?我在头文件classNSString*myurl=urlone中声明了跟踪的范围;NSLog(urlone);NSURL*url=[NSURL-URLWithString:myurl];[[UIApplication sharedApplication]openURL:url];它在通过nslogi进行跟踪时显示url猜测您忘记在urlone的初始化中添加@
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"https://example.com"] options:@{} completionHandler:nil];