iPhone';s粘贴板无法识别URL

iPhone';s粘贴板无法识别URL,iphone,url,uiwebview,clipboard,Iphone,Url,Uiwebview,Clipboard,我希望我的应用程序识别剪贴板的当前内容是否为URL,如果是,我希望它将该URL加载到web视图中 我使用以下语句进行此检查: if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.url-name"]]) ...code to load the URL into the webView 但它不起作用——IF语句总是返回FALSE,即使剪贴板的内容显然是一个URL 但奇怪的是,当我删除这

我希望我的应用程序识别剪贴板的当前内容是否为URL,如果是,我希望它将该URL加载到web视图中
我使用以下语句进行此检查:

 if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.url-name"]]) 
     ...code to load the URL into the webView
但它不起作用——IF语句总是返回FALSE,即使剪贴板的内容显然是一个URL
但奇怪的是,当我删除这个IF语句并继续将从剪贴板读取的URL加载到webView中时,它工作得非常好。所以它肯定只是IF语句,出于某种原因不起作用

以下是完整的代码:

// executed on a Button-click:
-(IBAction) showClipBoard {
    pasteboard = nil;  // resetting the pasteBoard each time
    pasteboard = [UIPasteboard generalPasteboard];
    NSURL *tempURL = pasteboard.URL;    

    //Check the pasteboard's value-type:
    if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.url-name"]]) {
      NSLog(@"URL is: %@", pasteboard.string);       
      NSURL *url = [NSURL URLWithString: pasteboard.string];
      NSURLRequest *req = [NSURLRequest requestWithURL: url];
      [webView loadRequest:req];   
  }
else 
    NSLog(@"=NOT a valid web-address");

NSString *tempString = [pasteboard valueForPasteboardType:@"public.utf8-plain-text"];

// Show the URL in a text-view box called "clipText":
clipText.text = tempString;
}


有人看到这里出了什么问题吗?

到现在为止,你可能已经明白了这一点,但是,我遇到了同样的问题&以下几点对我很有用:-

if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.url"]]) 
 ...code to load the URL into the webView