iphone 开发中使用zbar时遇到的几个典型问题解决方法。

来源:互联网 发布:淘货源软件下载 编辑:程序博客网 时间:2024/06/06 02:56
iphone 开发中使用zbar时遇到的几个典型问题解决方法。
 
在近期的一个ios项目中使用到了一个二维码扫描库(Qrcode)--ZBar, 期间遇到2个问题。
 
1. zbar下载后使用其libzbar.a 发现无法再arm7上运行。
2. zbar使用过程中,如果多次打开摄像头扫描Qrcode,会出现memory leak problem, 导致其内存指数型增长,大概8次调用后即耗费了85M 左右的内存, 最后导致app崩溃。
3. libzbar.a 在重新编译后, 无法再在simulator中运行,编译链接时出现错误提示:
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_ZBarReaderViewController", referenced from:
      objc-class-ref in HelloWorldViewController.o
  "_ZBarReaderControllerResults", referenced from:
      -[HelloWorldViewController imagePickerController:didFinishPickingMediaWithInfo:] in HelloWorldViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
 
1.libzbar.a无法编译链接成功的问题。
打开zbar.xcodeprj ,在指定的a7 simulator平台或者实机上重新编译,将libzbar.a替换原有的。
 
 
2. mem leak 问题的解决。
找到ZBarReaderViewController.m 修改其loadView方法,改成如下形式。
 
- (void) loadView
{
   self.view = [[[UIView alloc]
                   initWithFrame: CGRectMake (0 , 0 , 320 , 480 )] autorelease ];
}
 
添加了autorelease之后, 其内存使用状况就可以稳定在0.1M的范围内。
 
3. zbar的此问题出现的原因是: 在我解决上面的第二个问题时,只提取了Debug-iphoneos文件夹下的libzbar.a,此文件只能被实机link, 若要使得编译结果能device 和 simulator都能link, 可以依照如下方法解决。
主要思路:
1. 重编译时,设置Build Settings下的Architectures 和 valid Architectures为 arm64, armv7 , armv7s.
2. 重编译时,设置iOs deployment target 为ios 7.0 .
3. 在Product菜单中选择Schema->Edit Schema->Run->Build Configuration 为: Release。
4. 选择libzbar 分别选择不同实机和设备, 点击三角Run。
5. 在Xcode 工作区Products下非红色的libzbar.a ,右键找到其所在目录。 返回上一级
6. 运行: lipo -create Release-iphoneos/libzbar.a Release-iphonesimulator/libzbar.a -o libzbar.a
7. 拖拽 生成的libzbar.a 到 xcode 工程目录中, 选择copy到工作区。 
8. 完成!
 
 
参考:
http://stackoverflow.com/questions/22560899/xcode-5-1-undefined-symbols-for-architecture-x86-64-zbar
http://stackoverflow.com/questions/5387076/running-a-release-build-with-xcode-4
http://stackoverflow.com/questions/5287213/how-can-i-build-for-release-distribution-on-the-xcode-4
http://stackoverflow.com/questions/5706548/how-do-i-create-a-release-build-in-xcode-4
http://stackoverflow.com/questions/12339969/zbar-ifdef-issue-with-minizip-in-ios
http://stackoverflow.com/questions/18638319/zbar-memory-leak-on-ios
0 0