SFSafariViewController alloc initwithurl返回零

问题描述:

任何线索为什么SFSafariViewController是零?我似乎无法获得创建的Safari视图控制器。SFSafariViewController alloc initwithurl返回零

SFSafariViewController *safariViewController = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:menuItem.url]]; 
+2

您是否检查过URL的值?你检查过哪些iOS版本? – jcaron

+0

这可能是因为我正在使用8.2。我想我会在Xcode中得到一个错误,但我没有。现在加载9.2模拟器。 –

+0

你删除Xcode,虽然这可能是一个Xcode的问题????? –

想到我可能会得到一个错误,但如果使用iOS 9或更高版本的任何东西,它将返回nil。这似乎工作。

if ([SFSafariViewController class] != nil) { 
       SFSafariViewController *safariViewController = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:menuItem.url]]; 

       [self presentViewController:safariViewController animated:true completion:nil]; 
      } else { 
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:menuItem.url]]; 
      } 
+0

不要这样做,它甚至不会在iOS 10上工作。做'if([SFSafariViewController class]!= nil){' – dan

+0

Geez谢谢! –