diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index 11ef17a..b9ced41 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -20,7 +20,6 @@ #import "CDVCamera.h" #import "CDVJpegHeaderWriter.h" #import "UIImage+CropScaleOrientation.h" -#import #import #import #import @@ -38,9 +37,20 @@ static NSSet* org_apache_cordova_validArrowDirections; static NSString* toBase64(NSData* data) { SEL s1 = NSSelectorFromString(@"cdv_base64EncodedString"); SEL s2 = NSSelectorFromString(@"base64EncodedString"); - SEL realSel = [data respondsToSelector:s1] ? s1 : s2; - NSString* (*func)(id, SEL) = (void *)[data methodForSelector:realSel]; - return func(data, realSel); + SEL s3 = NSSelectorFromString(@"base64EncodedStringWithOptions:"); + + if ([data respondsToSelector:s1]) { + NSString* (*func)(id, SEL) = (void *)[data methodForSelector:s1]; + return func(data, s1); + } else if ([data respondsToSelector:s1]) { + 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; + } } @implementation CDVPictureOptions diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m index 4211198..d1da2fa 100644 --- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m +++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m @@ -476,7 +476,7 @@ pictureOptions.encodingType = EncodingTypePNG; resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataPNG base64EncodedString]); + XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataPNG base64EncodedStringWithOptions:0]); // Original, JPEG, full quality @@ -487,7 +487,7 @@ pictureOptions.encodingType = EncodingTypeJPEG; resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataJPEG base64EncodedString]); + XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataJPEG base64EncodedStringWithOptions:0]); // Original, JPEG, with quality value @@ -500,7 +500,7 @@ NSData* originalImageDataJPEGWithQuality = UIImageJPEGRepresentation(originalImage, [pictureOptions.quality floatValue]/ 100.f); resultData = [self.plugin processImage:originalImage info:@{} options:pictureOptions]; - XCTAssertEqualObjects([resultData base64EncodedString], [originalImageDataJPEGWithQuality base64EncodedString]); + XCTAssertEqualObjects([resultData base64EncodedStringWithOptions:0], [originalImageDataJPEGWithQuality base64EncodedStringWithOptions:0]); // TODO: usesGeolocation is not tested }