2013-08-07 38 views
0

有没有办法打开链接而不显示Safari?我的意思是它隐藏起来。在iPhone上启动Safari应用

这是我的代码。

NSString *WebURL = @"http://cvbn-dev.fgrhjnd.com/register.php"; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:WebURL]]; 
+0

你说的打开链接的意思,而不显示Safari和运行在隐藏?你在寻找一个webView吗? https://developer.apple.com/library/mac/#documentation/cocoa/Reference/WebKit/Classes/WebView_Class/Reference/Reference.html –

回答

0

如果您的目标是显示网站,您应该使用webview。如果通过“隐藏”,你的意思是你不想显示网站,但只是为了得到它的内容,你应该使用NSURL(https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html#//apple_ref/doc/uid/10000165i)或CFNetwork(http://developer.apple.com/library/mac/#documentation/Networking/Conceptual/CFNetwork/Concepts/Concepts.html#//apple_ref/doc/uid/TP30001132-CH4-SW10)。

0

添加到您的方法:

NSString *urlAddress = @"http://myurl.com"; 

//Create a URL object. 
NSURL *url = [NSURL URLWithString:urlAddress]; 

//URL Requst Object 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

//Load the request in the UIWebView. 
[WebView loadRequest:requestObj]; 
0

只需选中您的网址。

我查了,但是您的网址无效。

0

,如果你想显示一个网页,让你的用户注册(但不启动Safari浏览器),或者如果您要收集的数据和注册在后台的用户,而不显示页面目前尚不清楚。两者都有可能,但需要完全不同的解决方案。 Rajneesh071的答案中的WebView代码是前者的一个好地方,但您需要注意的是,如果您曾经在Web应用程序中关注过一个链接,那么您可能会启动Safari。你需要在你的javascript中使用像window.location ='newUrl'来改变页面。

如果您正在寻找后,开始与代码看起来是这样的:

NSURL* url = <create your URL>; 
NSString* postVariables = <post data in form format>; 
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url]; 

request.HTTPBody = [postVariables dataUsingEncoding:NSUTF8StringEncoding]; 
request.HTTPMethod = @"POST"; 
[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:^(NSURLResponse* pResponse, 
                 NSData* pData, 
                NSError* pError) 
{ <Process the response> } 
相关问题