How iOS repackaged the static library so that both the emulator and the real machine are available (take ZBARSDK as an example)

Source: Internet
Author: User

Zbarsdk:https://github.com/bmorton/zbarsdk

Http://zbar.sourceforge.net/iphone/index.html


1. Create the projectImport the SDK files for Zbar. Pull the ZBARSDK directory into the project, then select the Copy option2. Add the Framework
3. Add code
#import "ZBarSDK.h" #import "QRCodeGenerator.h" @interface Yxpviewcontroller () <zbarreaderdelegate, Uialertviewdelegate > @end @implementation yxpviewcontroller@synthesize imageview; @synthesize text; @synthesize label;-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super Initwithnibname:    Nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{[text Resignfirstresponder];}    -(void) viewdidload{[Super Viewdidload]; [email protected] "QR Code Editor";} Scan QR code-(ibaction) button: (ID) Sender {/* scan QR Code part: Import ZBARSDK file and introduce frame Avfoundation.framework Coremedia.frame Work corevideo.framework quartzcore.framework libiconv.dylib Introduction header file #import "ZBarSDK.h" can be used when the barcode is found, it executes Proxy Method-(void) Imagepickercontroller: (uiimagepickercontroller*) Reader didfinishpickingmediawithinfo: (Nsdictiona         ry*) Info Finally, the picture and contents of the barcode are read and displayed.    */Zbarreaderviewcontroller *reader = [Zbarreaderviewcontroller new];    Reader.readerdelegate = self;        Reader.supportedorientationsmask = Zbarorientationmaskall;        Zbarimagescanner *scanner = Reader.scanner;        [Scanner setsymbology:zbar_i25 config:zbar_cfg_enable to:0];    [Self presentmodalviewcontroller:reader animated:yes]; [Self Presentviewcontroller:reader animated:yes completion:nil];} -(Ibaction) Button2: (ID) Sender {/* character to QR code import Libqrencode File Introduction header file #import "QRCodeGenerator.h" to use */imagevie    W.image = [Qrcodegenerator qrImageForString:text.text imageSize:imageview.bounds.size.width];    }-(ibaction) Responder: (ID) Sender {//keyboard release [text Resignfirstresponder]; }//save photo to Local-(ibaction) SaveImage: (ID) Sender {if (imageview.image!=nil) {UIImage *aimage = Imageview.image        ; Uiimagewritetosavedphotosalbum (Aimage, Self, @selector (image:didfinishsavingwitherRor:contextinfo:), nil); }}-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) contextinfo{if (err or! = NULL) {Uialertview *photosave = [[Uialertview alloc] initwithtitle:@ "Save Error" message:[nsstring Stringwithforma        t:@ "%@", Error] delegate:nil Cancelbuttontitle:nil Otherbuttontitles:nil];        [Photosave show];    Photosave = nil; }else {Uialertview *photosave = [[Uialertview alloc] initwithtitle:@ "saved successfully" Message:nil Delegate:nil cancelButtonTi        Tle:nil Otherbuttontitles:nil];        [Photosave show];        The program automatically completes the Click Buttonindex button and dismiss the entire alertview operation [Photosave dismisswithclickedbuttonindex:0 Animated:yes];    Photosave = nil; }}-(void) Imagepickercontroller: (uiimagepickercontroller*) Reader didfinishpickingmediawithinfo: (NSDictionary*)    info{id<nsfastenumeration> results = [info objectforkey:zbarreadercontrollerresults];    Zbarsymbol *symbol = nil; For (the symbol in RESUlts) break;        Imageview.image = [info objectforkey:uiimagepickercontrolleroriginalimage];    [Reader Dismissmodalviewcontrolleranimated:yes];        [Reader Dismissviewcontrolleranimated:yes Completion:nil];    Determine if the header ' http: ' nsstring *regex = @ ' http+:[^\\s]* ' is included;        Nspredicate *predicate = [Nspredicate predicatewithformat:@ "Self MATCHES%@", regex];    Determine if the header ' SSID ' is included: ' NSString *ssid = @ ' ssid+:[^\\s]* ';;        Nspredicate *ssidpre = [Nspredicate predicatewithformat:@ "Self MATCHES%@", SSID];        Label.text = Symbol.data; if ([predicate evaluateWithObject:label.text]) {uialertview * alert = [[Uialertview alloc]initwithtitle:ni L message:@ "It would use the browser to this URL. "Delegate:nil Cancelbu ttontitle:@ "Close" Otherbuttontitles:@ "OK", nil];        Alert.delegate = self;        alert.tag=1;    [Alert show]; } else if ([Ssidpre EvaluateWithObject:label.text]) {Nsarray *arr = [Label.text Componentsseparatedbystri                Ng:@ ";"];                Nsarray * Arrinfohead = [[arr objectatindex:0] componentsseparatedbystring:@ ":"];                        Nsarray * Arrinfofoot = [[arr objectatindex:1] componentsseparatedbystring:@ ":"]; label.text= [NSString stringwithformat:@ "SSID:%@ \ n password:%@", [Arrinfohead Objectatindex:1],[arrinfofo                        OT Objectatindex:1]];                                                        Uialertview * alert = [[Uialertview alloc]initwithtitle:label.text                                                       message:@ "The password is copied to the Clipboard, it'll be redirected to the network settings interface" Delegate:nil cancelbuttontitle:@ "Clo                            Se                  otherbuttontitles:@ "OK", nil];        Alert.delegate = self;        alert.tag=2;                [Alert show];        Uipasteboard *pasteboard=[uipasteboard Generalpasteboard];    You can then use the following code to place a string on the Clipboard: pasteboard.string = [Arrinfofoot objectatindex:1]; }}
4. Compile and runIf you join a real-machine test, you can run it directly. If the emulator is running, you will need to repackage the LIBZBAR.A static library. Because, we downloaded the library is used for the real machine library, if running the program on the emulator, but also needs to regenerate. The steps are described below.
recompilation of static packages1. Add Targetin the original project, select the File->new->target->ios/framework & Library of the Xcode toolbar to create the Cocoa Touch Static Library project. The new project also has the XXX and xxxtests directories. The XXX directory also includes XXX.h and xxx.m header files. We can delete it here. 2. Add Zbarsdkunder the Xcode page, drag the zbarsdk you just downloaded to the XXX directory you just created, and select Copy. 3. Set architectures and valid architecturesSelect the project catalog->targets->xxx->build Settings, search for architectures and valid architectures, and change the two to arm64, ARMv7, armv7s, Also set the iOS Deployment target to iOS7.0 or higher. 4. Set schemaSelect the Project menu: Xxx->edit schema->run->build configuration is release. 5. Compilingafter setting the above steps, select XXX, click on the different simulator devices, run. 6. Generate a static libraryfind the Red LIBBER.A under the products in Xcode and right-click on the directory where it is located. Returns to the previous level. Execute the following command in the terminal:
Lipo  -create  Original LIBZBAR.A directory-  o  new Generation LIBZBAR.A Directory
find the LIBZBAR.A in the newly generated directory. 7. Re-import LIBZBAR.AReplace the original LIBZBAR.A with the one you built in the previous step. Run Success! 8.Some of the problems you may encounter

This section is reproduced from: http://www.cnblogs.com/ToDoToTry/p/3986366.html

1. Zbar download and use its LIBZBAR.A discovery can no longer run on ARM7. 2. Zbar the use of the process, if the camera scanning qrcode multiple times, will appear memory leak problem, resulting in the exponential growth of its ram, about 8 times after the call consumes about 85M of memory, and finally caused the app to crash. 3. LIBZBAR.A can no longer run in simulator after recompilation, error message when compiling Links: Undefined symbols for architecture armv7: "_objc_class_$_ Zbarreaderviewcontroller ", referenced from:objc-class-ref in HELLOWORLDVIEWCONTROLLER.O" _ZBarReaderControllerResul TS ", referenced from:-[helloworldviewcontroller imagepickercontroller:didfinishpickingmediawithinfo:] in HelloWorld ViewController.old:symbol (s) not found for Architecture Armv7clang:error:linker command failed with exit code 1 (use-v To see invocation) 1.LIBZBAR.A failed to compile the link success issue.  Open the ZBAR.XCODEPRJ and recompile on the specified A7 simulator platform or on the actual machine, replacing the LIBZBAR.A with the original. 2. Mem leak problem solving. Find ZBARREADERVIEWCONTROLLER.M Modify its Loadview method, change to the following form.- (void) Loadview{   Self.View= [[[UIViewAlloc]                  initWithFrame:CGRectMake (0,0, the,480 )]autorelease];} after adding autorelease, its memory usage can be stabilized in the range of 0.1M.

9. Reference documents:

http://blog.csdn.net/yxiaoping/article/details/39027079

http://blog.csdn.net/remote_roamer/article/details/7657845







How iOS repackaged the static library so that both the emulator and the real machine are available (take ZBARSDK as an example)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.