gpt4 book ai didi

objective-c - 从服务器下载 cocoa 包

转载 作者:行者123 更新时间:2023-12-03 17:41:56 24 4
gpt4 key购买 nike

如何从服务器下载 Cocoa .bundle 文件,然后将其加载到应用程序中?我尝试过使用 zip,但是 shouldDecodeSourceDataOfMIMEType 函数没有被调用。

- (IBAction)testDownload:(id)sender {
// Create the request.
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/SampleBundle.zip"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

// Create the connection with the request and start loading the data.
NSURLDownload *theDownload = [[NSURLDownload alloc] initWithRequest:theRequest
delegate:self];
if (theDownload) {
// Set the destination file.
[theDownload setDestination:@"/Users/developer/Desktop/Test-Downloads/SampleBundle" allowOverwrite:YES];
} else {
// inform the user that the download failed.
}
}


- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
download = nil;

// Inform the user.
NSLog(@"Download failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

- (void)downloadDidFinish:(NSURLDownload *)download
{
download = nil;

// Do something with the data.
NSLog(@"%@",@"downloadDidFinish");
}

- (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType;
{
BOOL shouldDecode = YES;
NSLog(@"EncodingType: %@",encodingType);
return shouldDecode;
}

那么如何从服务器下载 .bundle 将其解压缩并将其加载到应用程序中?

谢谢

最佳答案

根据下载的文档:shouldDecodeSourceDataOfMIMEType:

This method is not called if the downloaded file is not encoded.

所以,我猜这可能与此有关。您最好实现 download:didReceiveResponse: 并检查 NSURLResponse 对象,尤其是状态代码 - 如果不是 200,则说明出现了问题,您需要查看 HTTP 代码以了解问题到底是什么。

另外,我不确定这一点,您是否需要提升权限来安装 bundle (它是可执行文件)?

关于objective-c - 从服务器下载 cocoa 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10665206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com