Last active
December 11, 2015 13:38
-
-
Save jinqian/4608752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scannerController.rb | |
def session(session, didScan:result) | |
if (!result.nil?) | |
if (!(@result==result)) | |
@result = result.copy | |
@scannerSession.pause; | |
Dispatch::Queue.main.async{ | |
@overlayController.scanner(self, resultFound:result) | |
} | |
end | |
end | |
end | |
# OverlayController.rb | |
def scanner(scanner, resultFound:result) " | |
@scanner = scanner | |
type = result.getType | |
value = result.getValue | |
case type | |
when MS_RESULT_TYPE_IMAGE | |
resultStr = value | |
when MS_RESULT_TYPE_EAN8 | |
resultStr = "EAN 8: #{value}" | |
when MS_RESULT_TYPE_EAN13 | |
resultStr = "EAN 13: #{value}" | |
when MS_RESULT_TYPE_QRCode | |
resultStr = "QR Code: #{value}" | |
when MS_RESULT_TYPE_DMTX | |
resultStr = NSString.stringWithFormat("Datamatrix: #{value}") | |
else | |
resultStr = "<UNDEFINED>" | |
end | |
if ([email protected]?) | |
@actionSheet.dismissWithClickedButtonIndex(-1, animated:true) | |
@actionSheet = nil | |
end | |
@actionSheet = UIActionSheet.alloc.initWithTitle(resultStr, delegate: self, cancelButtonTitle: "OK", destructiveButtonTitle: nil, otherButtonTitles: nil) | |
@actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent | |
@actionSheet.showInView(self.view) | |
end | |
# .... | |
# .... | |
def actionSheet(actionSheet, clickedButtonAtIndex:buttonIndex) | |
if buttonIndex == 0 | |
@scanner.resume | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment