From 50d468b419c0a580ea634a14475bdd71eecb191c Mon Sep 17 00:00:00 2001 From: Alex Mouton Date: Thu, 16 Apr 2015 13:44:47 -0700 Subject: [PATCH] Conditionalized retain, autorelease, dealloc to compile in ARC configurations. --- src/ios/CDVBarcodeScanner.mm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ios/CDVBarcodeScanner.mm b/src/ios/CDVBarcodeScanner.mm index 2105d457c..5878b218e 100644 --- a/src/ios/CDVBarcodeScanner.mm +++ b/src/ios/CDVBarcodeScanner.mm @@ -30,6 +30,12 @@ - (BOOL)shouldAutorotate; @end +//------------------------------------------------------------------------------ +// +//------------------------------------------------------------------------------ + +#define CLEANUP_REFERENCES !__has_feature(objc_arc) + //------------------------------------------------------------------------------ // Adds a shutter button to the UI, and changes the scan from continuous to // only performing a scan when you click the shutter button. For testing. @@ -162,9 +168,11 @@ - (void)scan:(CDVInvokedUrlCommand*)command { parentViewController:self.viewController alterateOverlayXib:overlayXib ]; + #if CLEANUP_REFERENCES [processor retain]; [processor retain]; [processor retain]; + #endif // queue [processor scanBarcode] to run on the event loop [processor performSelector:@selector(scanBarcode) withObject:nil afterDelay:0]; } @@ -184,15 +192,22 @@ - (void)encode:(CDVInvokedUrlCommand*)command { stringToEncode: command.arguments[0][@"data"] ]; + #if CLEANUP_REFERENCES [processor retain]; [processor retain]; [processor retain]; + #endif // queue [processor generateImage] to run on the event loop [processor performSelector:@selector(generateImage) withObject:nil afterDelay:0]; } - (void)returnImage:(NSString*)filePath format:(NSString*)format callback:(NSString*)callback{ + #if CLEANUP_REFERENCES NSMutableDictionary* resultDict = [[[NSMutableDictionary alloc] init] autorelease]; + #else + NSMutableDictionary* resultDict = [[NSMutableDictionary alloc] init]; + #endif + [resultDict setObject:format forKey:@"format"]; [resultDict setObject:filePath forKey:@"file"]; @@ -288,7 +303,9 @@ - (void)dealloc { AudioServicesRemoveSystemSoundCompletion(_soundFileObject); AudioServicesDisposeSystemSoundID(_soundFileObject); + #if CLEANUP_REFERENCES [super dealloc]; + #endif } //-------------------------------------------------------------------------- @@ -703,7 +720,9 @@ - (void)dealloc { self.callback = nil; self.stringToEncode = nil; + #if CLEANUP_REFERENCES [super dealloc]; + #endif } //-------------------------------------------------------------------------- - (void)generateImage{ @@ -782,7 +801,9 @@ - (void)dealloc { self.shutterPressed = NO; self.alternateXib = nil; self.overlayView = nil; + #if CLEANUP_REFERENCES [super dealloc]; + #endif } //--------------------------------------------------------------------------