在iPhone应用程序上启动Safari

时间:2013-08-07 02:02:41

标签: iphone ios ipad

有没有办法在不显示Safari的情况下打开链接?我的意思是它在hide上运行。

这是我的代码。

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

4 个答案:

答案 0 :(得分:0)

如果您的目标是展示网站,则应使用网页浏览。如果通过“隐藏”表示您不想显示网站而仅仅是为了获取其内容,则应使用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)。

答案 1 :(得分: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];

答案 2 :(得分:0)

只需检查您的网址。

我已检查但您的网址无效。

答案 3 :(得分: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> }
相关问题