我正在构建一个应用程序,该应用程序在 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 = fileURL;
}
myFileURL 是一个全局变量,稍后会调用它来初始化 AVAudioPlayer,但是当我调用时
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:[myFileURL path]]){
NSLog(@"File DOES NOT exist at that url");
} else{
NSLog(@"File DOES exist at that url");
}
它表示该路径不存在文件。有什么想法或简单的方法来编写和访问从苹果服务器下载的应用程序购买内容吗?我还尝试将“/Contents/filename.mp3”添加到 URL 末尾,但无济于事。
最佳答案
关于ios - 访问从 Apple 托管的应用内购买下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17005020/