I want to add a QR Code Reader to my iOS app and i want it to run as fast as an app which is built in iPhone's or iPad's native language.
Adding the qr-reader-ane native extension to our app will solve our problem. It solved mine.
This recipe is an excerpt from my blog post available at http://www.nativext.com/ane-by-os/ios/qr-reader-native-extension/ Please refer to that post for full details.
NOTES:
As a first step, we will install the native extension to Flash Pro. To do this, click "File > ActionScript Settings", go to "Library Path" tab, click "Browse to a Native Extension (ANE) file", select your *.ane file (in this case it is QRZBarExtension.ane), click "Open" and "OK". You are done. You added the native extension to your project.
In the next steps, we will write the codes to the main .as file of the project. Open the main actionscript file and add this 4 lines of code to the top to import needed libraries to the project :
import com.rancondev.extensions.qrzbar.QRZBar; import com.rancondev.extensions.qrzbar.QRZBarEvent; import flash.display.MovieClip; import flash.events.*;
Later, lets define a variable to hold QR Code reader object :
private var qr:QRZBar;
Then we will write the function that starts qr code reading when you click a button :
protected function test(event:MouseEvent):void {
trace("button clicked");
qr = new QRZBar();
qr.scan();
qr.addEventListener( QRZBarEvent.SCANNED, scannedHandler );
}
Don't forget to attach this function to your SCAN button. Then as a last step, we will write the function that will work after scanner found a code :
protected function scannedHandler( event : QRZBarEvent ) : void {
qr.removeEventListener( QRZBarEvent.SCANNED, scannedHandler );
chosenlabel.text = event.result;
}
That's all. It is now ready to compile your app. Don't forget to use command prompt to publish your app. Here is the full sample code :
package {
import com.rancondev.extensions.qrzbar.QRZBar;
import com.rancondev.extensions.qrzbar.QRZBarEvent;
import flash.display.MovieClip;
import flash.events.*;
public class Example extends MovieClip {
private var qr:QRZBar;
public function Example()
{
}
protected function test(event:MouseEvent):void
{
trace("button clicked");
qr = new QRZBar();
qr.scan();
qr.addEventListener( QRZBarEvent.SCANNED, scannedHandler );
}
protected function scannedHandler( event : QRZBarEvent ) : void
{
qr.removeEventListener( QRZBarEvent.SCANNED, scannedHandler );
chosenlabel.text = event.result;
}
}
}
Please refer to the full blog post on my blog to download Flex or Flash Pro samples and some sample command promts to compile your app.
+