Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Played beep sound after scan succeeded.
Browse files Browse the repository at this point in the history
  • Loading branch information
khayong authored and Ryan Willoughby committed Mar 30, 2015
1 parent f04a2a0 commit b1bb4fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</config-file>

<resource-file src="src/ios/scannerOverlay.xib" />
<resource-file src="src/ios/CDVBarcodeScanner.bundle" />

<header-file src="src/ios/zxing-all-in-one.h" />

Expand All @@ -41,6 +42,7 @@
<framework src="QuartzCore.framework" />
<framework src="CoreGraphics.framework" />
<framework src="CoreImage.framework" />
<framework src="AudioToolbox.framework" />
</platform>

<!-- android -->
Expand Down
Binary file added src/ios/CDVBarcodeScanner.bundle/beep.caf
Binary file not shown.
12 changes: 12 additions & 0 deletions src/ios/CDVBarcodeScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <AudioToolbox/AudioToolbox.h>

//------------------------------------------------------------------------------
// use the all-in-one version of zxing that we built
Expand Down Expand Up @@ -247,6 +248,8 @@ @implementation CDVbcsProcessor
@synthesize is2D = _is2D;
@synthesize capturing = _capturing;

SystemSoundID _soundFileObject;

//--------------------------------------------------------------------------
- (id)initWithPlugin:(CDVBarcodeScanner*)plugin
callback:(NSString*)callback
Expand All @@ -264,6 +267,9 @@ - (id)initWithPlugin:(CDVBarcodeScanner*)plugin
self.is2D = YES;
self.capturing = NO;

CFURLRef soundFileURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("CDVBarcodeScanner.bundle/beep"), CFSTR ("caf"), NULL);
AudioServicesCreateSystemSoundID(soundFileURLRef, &_soundFileObject);

return self;
}

Expand All @@ -278,6 +284,11 @@ - (void)dealloc {
self.alternateXib = nil;

self.capturing = NO;

AudioServicesRemoveSystemSoundCompletion(_soundFileObject);
AudioServicesDisposeSystemSoundID(_soundFileObject);

[super dealloc];
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -322,6 +333,7 @@ - (void)barcodeScanDone {
- (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format {
dispatch_sync(dispatch_get_main_queue(), ^{
[self barcodeScanDone];
AudioServicesPlaySystemSound(_soundFileObject);
[self.plugin returnSuccess:text format:format cancelled:FALSE flipped:FALSE callback:self.callback];
});
}
Expand Down

0 comments on commit b1bb4fa

Please sign in to comment.