cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-plugin-file git commit: CB-9265 - mobilespec crashses on iPhone 6 Simulator
Date Thu, 02 Jul 2015 23:36:57 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 09132eb4e -> c23e46cc1


CB-9265 - mobilespec crashses on iPhone 6 Simulator


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

Branch: refs/heads/master
Commit: c23e46cc1abfaf7bb0c7655c8b436be511f46296
Parents: 09132eb
Author: Shazron Abdullah <shazron@gmail.com>
Authored: Thu Jul 2 16:36:52 2015 -0700
Committer: Shazron Abdullah <shazron@gmail.com>
Committed: Thu Jul 2 16:36:52 2015 -0700

----------------------------------------------------------------------
 src/ios/CDVFile.m | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c23e46cc/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index eec8978..9b3bb38 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -23,6 +23,25 @@
 #import "CDVAssetLibraryFilesystem.h"
 #import <objc/message.h>
 
+static NSString* toBase64(NSData* data) {
+    SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString");
+    SEL s2 = NSSelectorFromString(@"base64EncodedString");
+    SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:");
+    
+    if ([data respondsToSelector:s1]) {
+        NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1];
+        return func(data, s1);
+    } else if ([data respondsToSelector:s2]) {
+        NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s2];
+        return func(data, s2);
+    } else if ([data respondsToSelector:s3]) {
+        NSString* (*func)(id, SEL, NSUInteger) = (void *)[data methodForSelector:s3];
+        return func(data, s3, 0);
+    } else {
+        return nil;
+    }
+}
+
 CDVFile *filePlugin = nil;
 
 extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import));
@@ -878,12 +897,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
         [fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString*
mimeType, CDVFileError errorCode) {
             CDVPluginResult* result = nil;
             if (data != nil) {
-                SEL selector = NSSelectorFromString(@"cdv_base64EncodedString");
-                if (![data respondsToSelector:selector]) {
-                    selector = NSSelectorFromString(@"base64EncodedString");
-                }
-                id (*func)(id, SEL) = (void *)[data methodForSelector:selector];
-                NSString* b64Str = func(data, selector);
+                NSString* b64Str = toBase64(data);
                 NSString* output = [NSString stringWithFormat:@"data:%@;base64,%@", mimeType,
b64Str];
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:output];
             } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message