Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中单击按钮打开url_Iphone_Objective C - Fatal编程技术网

如何在iPhone中单击按钮打开url

如何在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]; 我认为它应该工作得很好,好的,

我在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];

我认为它应该工作得很好,好的,只是复制粘贴以下测试简单

 [[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];