Skip to main content
 首页 » 编程设计

ios之使用 Xcode 在 iOS 应用程序中调用网页

2024年01月01日102zdz8207

我如何在 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. 
} 

https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html