You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/02/11 00:23:00 UTC

[34/50] git commit: iOS: Add config preference for iOS persistent storage location

iOS: Add config preference for iOS persistent storage location


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/aaadfecb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/aaadfecb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/aaadfecb

Branch: refs/heads/master
Commit: aaadfecb7498673fba170d367c400fa258ab2d18
Parents: 590b930
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Jan 24 11:35:06 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Jan 24 11:38:20 2014 -0500

----------------------------------------------------------------------
 doc/index.md      | 31 +++++++++++++++++++++++++++++++
 src/ios/CDVFile.h |  2 --
 src/ios/CDVFile.m | 45 ++++++++++++++++++++++++++++++++-------------
 3 files changed, 63 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 0c26700..192cae5 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -55,3 +55,34 @@ on the subject. For an overview of other storage options, refer to Cordova's
 - `FileReader.readAsText(blob, encoding)`
   - The `encoding` parameter is not supported, and UTF-8 encoding is always in effect.
 
+### iOS Persistent storage location
+
+There are two valid locations to store persistent files on an iOS device: the
+Documents directory and the Library directory. Previous versions of thie plugin
+only ever stored persistent files in the Documents directory. This had the
+side-effect of making all of an application's files visible in iTunes, which
+was often unintended, especially for applications which handle lots of small
+files, rather than producing complete documents for export, which is the
+intended purpose of the directory.
+
+It is now possible to choose whether to store files in the documents or library
+directory, with a preference in your application's config.xml file. To do this,
+add one of these two lines to config.xml:
+
+    <preference name="iosPersistentFileLocation" value="Library" />
+
+    <preference name="iosPersistentFileLocation" value="Documents" />
+
+Without this line, the File plugin will not initialize, and your application
+will not start.
+
+If your application has previously been shipped to users, using an older (pre-
+1.0) version of this plugin, and has stored files in the persistent filesystem,
+then you should set the preference to "Documents". Switching the location to
+"Library" would mean that existing users who upgrade their application would be
+unable to access their previously-stored files.
+
+If your application is new, or has never previously stored files in the
+persistent filesystem, then the "Library" setting is generally recommended,
+unless your application's purpose is to generate document files for users to
+consume externally.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 85a76b0..477fad7 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -90,8 +90,6 @@ typedef int CDVFileError;
     NSString* appDocsPath;
     NSString* appLibraryPath;
     NSString* appTempPath;
-    NSString* persistentPath;
-    NSString* temporaryPath;
 
     NSMutableArray* fileSystems_;
     BOOL userHasAllowed;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index f4f1cbb..e685929 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -153,7 +153,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 
 @implementation CDVFile
 
-@synthesize appDocsPath, appLibraryPath, appTempPath, persistentPath, temporaryPath, userHasAllowed, fileSystems=fileSystems_;
+@synthesize appDocsPath, appLibraryPath, appTempPath, userHasAllowed, fileSystems=fileSystems_;
 
 - (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
     [fileSystems_ addObject:fs];
@@ -182,35 +182,54 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     }
 }
 
+@synthesize viewController=_viewController;
+- (void)setViewController:(UIViewController *)newViewController
+{
+    if (_viewController != newViewController) {
+        _viewController = newViewController;
+
+        NSString *location = nil;
+        if([_viewController isKindOfClass:[CDVViewController class]]) {
+            CDVViewController *vc = (CDVViewController *)_viewController;
+            NSMutableDictionary *settings = vc.settings;
+            location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString];
+            NSAssert(
+                [location isEqualToString:@"library"] || [location isEqualToString:@"documents"],
+                @"File plugin configuration error: Please set ios-persistent-file-location in config.xml to one of \"library\" (for new applications) or \"documents\" (for compatibility with previous versions)");
+        }
+
+        [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
+        if ([location isEqualToString:@"library"]) {
+            [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
+        } else {
+            // Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
+            [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appDocsPath]];
+        }
+        [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
+    }
+}
+
+
 - (id)initWithWebView:(UIWebView*)theWebView
 {
     self = (CDVFile*)[super initWithWebView:theWebView];
     if (self) {
         filePlugin = self;
-//        @throw (@"Error!");
         [NSURLProtocol registerClass:[CDVFilesystemURLProtocol class]];
 
         fileSystems_ = [[NSMutableArray alloc] initWithCapacity:3];
 
-        // get the temporary directory path
+        // Get the Library directory path
         NSArray* paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
         self.appLibraryPath = [paths objectAtIndex:0];
 
+        // Get the Temporary directory path
         self.appTempPath = [NSTemporaryDirectory()stringByStandardizingPath];   // remove trailing slash from NSTemporaryDirectory()
 
-        [fileSystems_ addObject:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:[paths objectAtIndex:0]]];
-
-        // get the documents directory path
+        // Get the Documents directory path
         paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         self.appDocsPath = [paths objectAtIndex:0];
 
-        [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths objectAtIndex:0]]];
-
-        self.persistentPath = [NSString stringWithFormat:@"/%@", [self.appDocsPath lastPathComponent]];
-        self.temporaryPath = [NSString stringWithFormat:@"/%@", [self.appTempPath lastPathComponent]];
-        // NSLog(@"docs: %@ - temp: %@", self.appDocsPath, self.appTempPath);
-        
-        [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
 
     }