gpt4 book ai didi

Objective-C 尝试从短网址下载 PDF

转载 作者:IT老高 更新时间:2023-10-28 13:03:15 27 4
gpt4 key购买 nike

我一直在尝试让它工作,而不是先将它加载到 Web View 上并从中获取 absoluteString,以便我可以下载 URL。我尝试了许多 shortURL 解决方案,但它们从未完全加载 URL。他们总是给我一个不是最终网址的网址,也不是 PDF 网址。任何帮助都会很棒。我正在尝试在应用程序首次打开或检查更新时下载 PDF,但当时它只获取短 url,我必须等到调用 web View 才能获取完整的 url 才能下载PDF 占了上风。

最佳答案

您下载 PDF,就像下载任何其他文件一样。

看看NSURLDownload

- (void)startDownloadingURL:sender
{
// Create the request.
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

// Create the download with the request and start loading the data.
NSURLDownload *theDownload = [[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
if (!theDownload) {
// Inform the user that the download failed.
}
}

- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
{
NSString *destinationFilename;
NSString *homeDirectory = NSHomeDirectory();

destinationFilename = [[homeDirectory stringByAppendingPathComponent:@"Desktop"]
stringByAppendingPathComponent:filename];
[download setDestination:destinationFilename allowOverwrite:NO];
}


- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
// Dispose of any references to the download object
// that your app might keep.
...

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

- (void)downloadDidFinish:(NSURLDownload *)download
{
// Dispose of any references to the download object
// that your app might keep.
...

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

关于Objective-C 尝试从短网址下载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36705112/

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