ios - 访问从 Apple 托管的应用内购买下载的文件

标签 ios xcode ios6 in-app-purchase storekit

我正在构建一个应用程序,该应用程序在 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 末尾,但无济于事。

最佳答案

使用此处找到的代码解决:http://xinsight.ca/blog/iap-content-download-in-ios6

关于ios - 访问从 Apple 托管的应用内购买下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17005020/

相关文章:

ios - CAShapeLayer strokeStart 和 strokeEnd 位置

ios - 移除移动的 GMSPolyline 线段

iOS 图表,Swift 2.1.1 Xcode 7.2 似乎不起作用,

ios - iPhone 6 和 6 plus 屏幕像素大小?

ios - UICollectionView:-[UICollectionView _endItemAnimations] 中的断言失败

html - Google Analytics for HTML inside ios native app

iOS Swift - 动态增加 UITextView 和父 UIView 的高度

c++ - 为 Clang 静态分析器编写自定义检查器

iphone - 如何创建笔记本并将我的笔记保存在该笔记本中?

iphone - iOS GPS 数据问题