0

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

这是我的代码。

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

4 回答 4

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> }
于 2013-08-08T02:04:52.393 回答
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];
于 2013-08-07T04:41:37.970 回答
0

只需检查您的网址。

我检查了,但您的 URL 无效。

于 2013-08-07T06:04:52.943 回答
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)。

于 2013-08-07T02:59:26.540 回答