2

I've got the point where I am downloading the hosted In-App Purchase. It downloads the hosted In App Purchase content to the Cache directory, but as I need hosted In App Purchase content to be permanent I need to move it to the Documents directory.

Once it is in there I then need to actually access the contents.

I am using

    NSURL *url = download.contentURL;
    NSError *error = nil;
    NSArray *properties = [NSArray arrayWithObjects: NSURLLocalizedNameKey,
                           NSURLCreationDateKey, NSURLLocalizedTypeDescriptionKey, nil];

    NSArray *zipContentsArray = [[NSFileManager defaultManager]
                      contentsOfDirectoryAtURL:url
                      includingPropertiesForKeys:properties
                      options:(NSDirectoryEnumerationSkipsHiddenFiles)
                      error:&error];

Which shows the output in the Cache

The download's contentURL is
file:///private/var/mobile/Applications/**/Library/Caches/***.zip/

zipContentsArray = (
    "file:///private/var/mobile/Applications/***/Library/Caches/***.zip/ContentInfo.plist",
    "file:///private/var/mobile/Applications/***/Library/Caches/***.zip/Contents/",
    "file:///private/var/mobile/Applications/**/Library/Caches/***.zip/META-INF/"
)

How would I get to the Contents (even from within the Caches folder - it would be the same process regardless of its location, I'm assuming)?

It's maddening how little documentation there is from Apple surrounding this whole process, so any help would be very greatly received.

daihovey
  • 3,485
  • 13
  • 66
  • 110
  • "It downloads it to the Cache directory": what is "It"? This seems to be a question about moving a directory recursively; is that correct? – trojanfoe Jul 09 '14 at 06:42
  • @trojanfoe "it" is the hosted In App Purchase content - I guess the question is two part: firstly how do I move the downloaded content from the Caches directory to the Documents directory. Secondly, how do I use it once I have. – daihovey Jul 09 '14 at 06:58
  • Caches directory would only be deleted if the user uninstalled the app (or you provided an interface to clear the cache). Any reason you don't want to keep it there? Also, the documents directory is visible to the user, so you may not want that at all. – brandonscript Jul 09 '14 at 07:20
  • @remus What is the norm for IAPs - say a game level or audio? In Apple's docs they say "After the download completes, your app is responsible for moving it to the appropriate location." which implies it should be moved. It also says "For content that can be deleted if the device runs out of disk space (and later re-downloaded by your app), leave the files in the Caches directory. Otherwise, move the files to the Documents folder and set the flag to exclude them from user backups." Caches would be removed if the device ran out of space. – daihovey Jul 09 '14 at 08:19
  • Aye, that's a fair point. You probably want to keep it in docs then. – brandonscript Jul 09 '14 at 08:20
  • Crap: http://stackoverflow.com/questions/14790302/where-to-store-downloadable-in-app-purchases – brandonscript Jul 09 '14 at 08:57
  • @remus hmmm, the documentation (https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html#//apple_ref/doc/uid/TP40008267-CH5-SW5) says Documents folder `Otherwise, move the files to the Documents folder and set the flag to exclude them from user backups.` – daihovey Jul 09 '14 at 09:58
  • Yeah, so in short I don't think anyone really nows. Library might be a great choice though, since it's neither Docs nor Cache ;) – brandonscript Jul 09 '14 at 15:58

1 Answers1

1

I am currently at the same problem though I may be able to give you some further step forward. Your right in that your content must be moved from the cache, this is stated in the Apple IAP guideline. I'm trying to download content for a non-consumable IAP and move its content to the correct path. I've managed to get the downloaded content to the iphone cache but now need to pass this content to the correct path.

I've used some code from http://xinsight.ca/blog/iap-content-download-in-ios6/ and this seems what I need; however i'm not sure which path I need to state for my app bundle. From the code, this seems to relate to 'MyConfig'

- (void) processDownload:(SKDownload*)download;
{
// convert url to string, suitable for NSFileManager
NSString *path = [download.contentURL path];

// files are in Contents directory
path = [path stringByAppendingPathComponent:@"Contents"];

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSArray *files = [fileManager contentsOfDirectoryAtPath:path error:&error];
NSString *dir = [MyConfig downloadableContentPathForProductId:download.contentIdentifier]; // not written yet

for (NSString *file in files) {
    NSString *fullPathSrc = [path stringByAppendingPathComponent:file];
    NSString *fullPathDst = [dir stringByAppendingPathComponent:file];

    // not allowed to overwrite files - remove destination file
    [fileManager removeItemAtPath:fullPathDst error:NULL];

    if ([fileManager moveItemAtPath:fullPathSrc toPath:fullPathDst error:&error] == NO) {
        NSLog(@"Error: unable to move item: %@", error);
    }
}

can someone add to this so we can both make some progress please?

Slarty Bartfast
  • 635
  • 7
  • 13
  • Just to add to the above; Apple IAP Programming Guide states "The files are saved in the caches directory with the backup flag unset. After download completes, your app is responsible for moving them to the appropriate location. For content that can be deleted if the device runs out of space ... leave the files in the caches directory. Otherwise move them to the Documents folder and set flag to exclude them from user backups." So i guess we need the correct path to the Documents directory. – Slarty Bartfast Jul 11 '14 at 11:49