【问题标题】:Accessing Files Downloaded from Apple-Hosted In-App Purchase访问从 Apple 托管的应用内购买中下载的文件
【发布时间】:2014-06-22 06:07:55
【问题描述】:

我正在构建一个应用,它在 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");
    }

它表示该路径中不存在文件。任何想法或简单的方法来编写和访问从苹果服务器下载的应用购买内容?我还尝试在 URL 末尾添加“/Contents/filename.mp3”,但无济于事。

【问题讨论】:

  • 我使用了您的代码-(void)downloadFromURL: (NSURL *) temporaryURL 并收到了日志消息File successfully downloaded. Url is file:///var/mobile/Applications/B8ED2BDF-513B-479F-92EA-A23C3C0725C0/Documents/C6011299-89C0-4D61-96BF-572D7EF3793E.zip。但是,当我使用 iExplorer 查看 Documents 文件夹时,我看不到任何复制的文件。知道如何解决吗?

标签: ios xcode ios6 in-app-purchase storekit


【解决方案1】:

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

【讨论】:

  • 您好我有同样的问题,我很难理解我在您发布的链接中的“MyConfig”中必须做什么,请您帮帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-03
  • 1970-01-01
  • 2013-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多