Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Fix for #84
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Jan 17, 2016
1 parent e95a259 commit b2df599
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/ios/Model/HCPFilesStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,29 @@ - (instancetype)initWithReleaseVersion:(NSString *)releaseVersion {
}

+ (NSURL *)pluginRootFolder {
NSURL *supportDir = [[NSFileManager defaultManager] applicationSupportDirectory];
return [supportDir URLByAppendingPathComponent:CHCP_FOLDER isDirectory:YES];
// static decleration gets executed only once
static NSURL *_pluginRootFolder = nil;
if (_pluginRootFolder != nil) {
return _pluginRootFolder;
}

// construct path to the folder, where we will store our plugin's files
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *supportDir = [fileManager applicationSupportDirectory];
_pluginRootFolder = [supportDir URLByAppendingPathComponent:CHCP_FOLDER isDirectory:YES];
if (![fileManager fileExistsAtPath:_pluginRootFolder.path]) {
[fileManager createDirectoryAtURL:_pluginRootFolder withIntermediateDirectories:YES attributes:nil error:nil];
}

// we need to exclude plugin's root folder from the iCloud backup, or it can become too big and Apple will reject the app.
// https://developer.apple.com/library/ios/qa/qa1719/_index.html
NSError *error = nil;
BOOL success = [_pluginRootFolder setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
if (!success) {
NSLog(@"Error excluding %@ from backup %@", [_pluginRootFolder lastPathComponent], error);
}

return _pluginRootFolder;
}

- (void)localInitWithReleaseVersion:(NSString *)releaseVersion {
Expand Down

0 comments on commit b2df599

Please sign in to comment.