我如何在 iOS 应用程序中调用网页(访问它而不在显示器上显示)? 我希望能够拥有一个 iOS 应用程序,当打开时,将在后台加载一个网页,这将执行一个 shell 脚本。
请您参考如下方法:
我认为您应该将 NSURLConnection 与您的 URL 一起使用,并忽略收到的数据。 查看 Apple 文档:
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData dataWithCapacity: 0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!theConnection) {
// Release the receivedData object.
receivedData = nil;
// Inform the user that the connection failed.
}