我正在构建一个应用程序,它在Apple的服务器上托管了非消费类应用内购买.我已经成功地将我的应用内购买下载,但是当我将它们保存到文档目录中时,我似乎无法找到或访问它们.
这是我用来从下载的contentURL下载文件的功能.下载完成后调用它,传入download.contentURL将其在缓存中的位置移动到文档文件夹.
-(void)downloadFromURL: (NSURL *) temporaryURL {
NSLog(@"The download's contentURL is %@", temporaryURL.absoluteString);
NSString *folderName = [[temporaryURL path] lastPathComponent];
NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folder = [pathArr objectAtIndex:0];
NSString *filePath = [folder stringByAppendingPathComponent:folderName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSError *writeError = nil;
NSData *downloadData = [[NSData alloc] initWithContentsOfURL:temporaryURL];
[downloadData writeToURL: fileURL options:0 error:&writeError];
if( writeError) {
NSLog(@"Error in writing file %@' : \n %@ ", filePath , writeError);
return;
}
NSLog(@"File successfully downloaded. Url is %@",fileURL.absoluteString);
myFileURL = …Run Code Online (Sandbox Code Playgroud)