Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionalized retain, autorelease, dealloc for ARC configurations #270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ios/CDVBarcodeScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];
}
Expand All @@ -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"];

Expand Down Expand Up @@ -288,7 +303,9 @@ - (void)dealloc {
AudioServicesRemoveSystemSoundCompletion(_soundFileObject);
AudioServicesDisposeSystemSoundID(_soundFileObject);

#if CLEANUP_REFERENCES
[super dealloc];
#endif
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -703,7 +720,9 @@ - (void)dealloc {
self.callback = nil;
self.stringToEncode = nil;

#if CLEANUP_REFERENCES
[super dealloc];
#endif
}
//--------------------------------------------------------------------------
- (void)generateImage{
Expand Down Expand Up @@ -782,7 +801,9 @@ - (void)dealloc {
self.shutterPressed = NO;
self.alternateXib = nil;
self.overlayView = nil;
#if CLEANUP_REFERENCES
[super dealloc];
#endif
}

//--------------------------------------------------------------------------
Expand Down