You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/23 20:57:18 UTC

[22/37] git commit: ios: Style: plugin initialization

ios: Style: plugin initialization

Use pluginInitialize rather than setViewController for initialization


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/23058965
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/23058965
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/23058965

Branch: refs/heads/master
Commit: 2305896506e43394141dccb5feaa70b6e9b14910
Parents: 0af8049
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Apr 3 14:21:58 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Apr 4 09:27:48 2014 -0400

----------------------------------------------------------------------
 src/ios/CDVFile.m | 81 +++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/23058965/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 02cc6a5..e87e7dc 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -199,57 +199,52 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     }
 }
 
-@synthesize viewController=_viewController;
-- (void)setViewController:(UIViewController *)newViewController
+- (void)pluginInitialize
 {
-    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];
-        }
-        if (location == nil) {
-            // Compatibilty by default (if the config preference is not set, or
-            // if we're not embedded in a CDVViewController somehow.)
-            location = @"compatibility";
-        }
+    NSString *location = nil;
+    if([self.viewController isKindOfClass:[CDVViewController class]]) {
+        CDVViewController *vc = (CDVViewController *)self.viewController;
+        NSMutableDictionary *settings = vc.settings;
+        location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString];
+    }
+    if (location == nil) {
+        // Compatibilty by default (if the config preference is not set, or
+        // if we're not embedded in a CDVViewController somehow.)
+        location = @"compatibility";
+    }
 
-        NSError *error;
-        if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appTempPath
+    NSError *error;
+    if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appTempPath
+                                  withIntermediateDirectories:YES
+                                                   attributes:nil
+                                                        error:&error]) {
+        [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
+    } else {
+        NSLog(@"Unable to create temporary directory: %@", error);
+    }
+    if ([location isEqualToString:@"library"]) {
+        if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appLibraryPath
                                       withIntermediateDirectories:YES
                                                        attributes:nil
                                                             error:&error]) {
-            [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
-        } else {
-            NSLog(@"Unable to create temporary directory: %@", error);
-        }
-        if ([location isEqualToString:@"library"]) {
-            if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appLibraryPath
-                                          withIntermediateDirectories:YES
-                                                           attributes:nil
-                                                                error:&error]) {
-                [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
-            } else {
-                NSLog(@"Unable to create library directory: %@", error);
-            }
-        } else if ([location isEqualToString:@"compatibility"]) {
-            /*
-             *  Fall-back to compatibility mode -- this is the logic implemented in
-             *  earlier versions of this plugin, and should be maintained here so
-             *  that apps which were originally deployed with older versions of the
-             *  plugin can continue to provide access to files stored under those
-             *  versions.
-             */
-            [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.rootDocsPath]];
+            [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
         } else {
-            NSAssert(false,
-                @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
+            NSLog(@"Unable to create library directory: %@", error);
         }
-        [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
+    } else if ([location isEqualToString:@"compatibility"]) {
+        /*
+         *  Fall-back to compatibility mode -- this is the logic implemented in
+         *  earlier versions of this plugin, and should be maintained here so
+         *  that apps which were originally deployed with older versions of the
+         *  plugin can continue to provide access to files stored under those
+         *  versions.
+         */
+        [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.rootDocsPath]];
+    } else {
+        NSAssert(false,
+            @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
     }
+    [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
 }