神羲龛

路漫漫其修远兮,到此为止吧

创建Tweak时遇到的问题及其解决方法

问题1:

dpkg: status database area is locked by another process
make: *** [internal-install] Error 2

解决办法:

重启SpringBoard即可

问题2:

Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_UIAlertView", referenced from:
  objc-class-ref in Tweak.xm.e98a028e.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [obj/iOSRE.dylib.ba964c90.unsigned] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [iOSRE.all.tweak.variables] Error 2

解决方法:

在MakeFile中加入  xxx_FRAMEWORKS = UIKit
将xxx替换成你的TWEAK_NAME

问题3:

iosre/theos/makefiles/targets/Darwin/iphone.mk:41: Deploying to iOS 3.0 while building for 6.0 will generate armv7-only binaries.

解决方法:

在MakeFile中加入 ARCHS = armv7 armv7s

以上就是一些搜集到的解决方法,仅供参考,到此为止吧

参考链接:Important: Update your tweaks to support arm64

解决IOS状态栏高度变化对View的影响

在IOS应用中会遇到状态栏高度的变化,比如手机来电话和手机设置热点。 这时statusBarFrame.size.height=40;并且self.view回整体向下偏移20的高度,如果程序界面中的底部有一些视图是根据self.view.frame.size.height来设置位置的,那么就会被遮挡,这真悲剧。

UIApplicationWillChangeStatusBarFrameNotification是用来通知状态栏的改变,据此便可以相应调整视图的位置

如果在statusBarFrame变化之前对self.view的transform做了改变,那么此时self.view.frame不再是(0,0,320,568) 因为view.frame是根据view.bounds和view.center来确定的,所以可以由此来重新调整self.view.frame

OK,做个标记,到此为止吧

搭建一个网页抓取服务

这是一个基于python的网页抓取服务,主要用到两个第三方库,即PhantomJS和Selenium,当然具体解析网页还需要别的库,之后用到再说。

PhantomJS:是一个基于WebKit的服务器端 JavaScript API。它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, JSON, Canvas, 和 SVG。PhantomJS可以用于页面自动化,网络监测,网页截屏,以及无界面测试等。

Selenium:是一个自动化web应用程序测试工具,在这里我们使用的是Python的一个模块

我所使用的系统是centos6.5,已安装好python环境,接下来需要安装django:一个开放源代码的Web应用框架,由Python写成,采用了MVC的软件设计模式.

安装Django

在安装Django之前需要安装两个小工具easy_install和virtualenv

1、easy_install和pip:很多情况下我们都需要给python安装很多的第三方扩展包,安装这些包有点小繁琐,而easy_install和pip可以一键安装,方便又容易。

* sudo python setup.py install
* which easy_install
* #/usr/bin/easy_install
* sudo easy_install pip

2、virtualenv和virtualenvwrapper:一种源代码版本管理工具,可以使每个project都有自己独立的虚拟环境。

* sudo easy_install virtualenv virtualenvwrapper

安装好virtualenvvirtualenvwrapper之后,需要配置一下环境,在home目录下打开.bashrc

if [ -f /usr/local/bin/virtualenvwrapper.sh]; then   export VENVWRAP=/usr/local/bin/virtualenvwrapper.sh
fi
if [ ! -z $VENVWRAP]; then   [ -d $HOME/sites/env ] || mkdir -p $HOME/sites/env
      export WORKON_HOME=$HOME/sites/env
      source $VENVWRAP
      export VIRTUALENV_USE_DISTRIBUTE=true
      export PIP_VIRTUALENV_BASE=$WORKON_HOME
      export PIP_REQUIRE_VIRTUALENV=true
      export PIP_RESPECT_VIRTUALENV=true
      export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
fi

将以上代码加入.bashrc,然后source .bashrc

以下是在安装过程中可能会遇到的一些问题

如果遇到:

Traceback (most recent call last):
    File "/usr/bin/easy_install", line 5, in <module>
    from pkg_resources import load_entry_point
    File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2720, in <module>
    File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 588, in resolve
    pkg_resources.DistributionNotFound: setuptools==3.0dev

解决方法:

wget http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py 

如果遇到

Traceback (most recent call last):
File "distribute_setup.py", line 556, in <module>
sys.exit(main())
File "distribute_setup.py", line 552, in main
tarball = download_setuptools(download_base=options.download_base)
File "distribute_setup.py", line 211, in download_setuptools
src = urlopen(url)
File "/usr/local/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/local/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/local/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python2.7/urllib2.py", line 442, in error
result = self._call_chain(*args)
File "/usr/local/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.7/urllib2.py", line 629, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/local/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/local/lib/python2.7/urllib2.py", line 427, in _open
'unknown_open', req)
File "/usr/local/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.7/urllib2.py", line 1247, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: https>

解决办法:

sudo yum install openssl-devel

好了,先创建一个虚拟环境

mkvirtualenv yichangxi

创建一个requirements.txt,内容是django

安装Django

pip install -r requirements.txt

访问localhost:8080就可以看到Django的欢迎页了。

因为我是用vagrant在本机(mac)虚拟的centos,所以为了可以使本地与虚拟的系统中的Django服务进行通信,所以安装了Tengine.OK

接下来我们需要安装这几个第三方模块,simplepython,BeautifulSoup,selenium,pylibmc.

如果在安装pylibmc时遇到问题:

    Command /home/vagrant/sites/env/xxx/bin/python -c "import setuptools, tokenize;__file__='/home/vagrant/sites/env/xxx/build/pylibmc/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-DvN1EK-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/vagrant/sites/env/xxx/include/site/python2.7 failed with error code 1 in /home/vagrant/sites/env/xxx/build/pylibmc
Storing debug log for failure in /home/vagrant/.pip/pip.log

解决办法:

sudo yum install libmemcached-devel zlib1g-devel libssl-devel python-devel build-essential

如果遇到:

    RuntimeError: pylibmc requires >= libmemcached 0.32, was compiled with 0.31

解决办法:

    cd /usr/local/lib/
    ln -s libmemcached.so libmemcached.so.11
    sudo ldconfig
    ldconfig -p | grep libmemcached查看一下
    安装libmemcached 0.32,重新安装pylibmc

如果遇到:

    django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

解决办法:

sudo yum install pysqlite

如果遇到:

/usr/bin/yum: line 2: import: command not found
/usr/bin/yum: line 3: try:: command not found
/usr/bin/yum: line 4: import: command not found
/usr/bin/yum: line 5: except: command not found
/usr/bin/yum: line 23: syntax error near unexpected token `('
/usr/bin/yum: line 23: `""" % (sys.exc_value, sys.version)'

解决办法:

vi /usr/bin/yum
第一行修改为 :#!/usr/bin/python2.6

如果遇到:

pip install pylibmc
python2.7:
running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

creating build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/test.py -> build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/consts.py -> build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/__main__.py -> build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/pools.py -> build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/__init__.py -> build/lib.linux-x86_64-2.7/pylibmc

copying src/pylibmc/client.py -> build/lib.linux-x86_64-2.7/pylibmc

running build_ext

building '_pylibmc' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/src

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DUSE_ZLIB -I/usr/local/include/python2.7 -c src/_pylibmcmodule.c -o build/temp.linux-x86_64-2.7/src/_pylibmcmodule.o -fno-strict-aliasing

In file included from src/_pylibmcmodule.c:34:

src/_pylibmcmodule.h:189: error: ‘MEMCACHED_BEHAVIOR_TCP_KEEPALIVE’ undeclared here (not in a function)

src/_pylibmcmodule.h:256: error: ‘MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY’ undeclared here (not in a function)

src/_pylibmcmodule.h:256: error: initializer element is not constant

src/_pylibmcmodule.h:256: error: (near initialization for ‘PylibMC_distributions[3].flag’)

src/_pylibmcmodule.h:261: error: ‘MEMCACHED_DISTRIBUTION_CONSISTENT_MAX’ undeclared here (not in a function)

src/_pylibmcmodule.h:261: error: initializer element is not constant

src/_pylibmcmodule.h:261: error: (near initialization for ‘PylibMC_distributions[5].flag’)

error: command 'gcc' failed with exit status 1

解决办法:

这个错误的出现是因为libmemcached的版本与pylibmc的版本不匹配造成的,所以安装相对应的libmemcached与pylibmc即可

未完待续~

在IOS应用中使用字体图标

做IOS开发的都知道,因为屏幕分辨率的问题,在ios app 中都得放两套切图来支持retina屏和非retina屏幕,但是文字就不需要考虑分辨率的问题,所以可不可以将一些图片用文字来代替呢,省时省力省资源。看下面一些截图:

这些截图上面的图标都是用文字来表示的,没有用png图片,看起来还不错吧

下面介绍一下制作以及使用图标字体的方法

字体图标的制作

这部分分两个步骤:1、字形图标的制作 2、字体库的制作

一、字形图标的制作

安装一个工具Illustrator,这个工具有破解版,自行搜寻下载

使用其中的钢笔工具绘制字形图标,比如绘制一个新浪微博logo和垃圾桶,如图:

新浪微博logo

垃圾桶

好了,绘制完字形图标,接下来做字体库

二、字体库的制作

安装FontLab Studio,这个工具可以生成字体库 new—>generate font,生成.ttf文件,打开该ttf文件,选中一个字形,打开,然后将做好的字形图标从Illustrator中copy过来,这里有个尺寸问题,可以参看这篇文章Illustrator+FontLab进行字体设计教程 保存,ok。

字体图标的使用

将制作好的字体库copy到工程中,在IOS工程中配置一下,打开appName-Info.plist,添加属性Fonts provided by application,如图:

因为字体图标也是字体,所以使用和普通的字体没区别:看代码就知道了

StrokeLabel *cameraLabel = [[StrokeLabel alloc] initWithFrame:CGRectMake(175, headerImageView.frame.origin.y + 70, 54, 46) LineWidth:5 TextColor:[UIColor whiteColor]];
cameraLabel.text = @"C";
cameraLabel.textAlignment = NSTextAlignmentCenter;
cameraLabel.textColor= [UIColor colorWithHexString:@"#8dc63f"];
cameraLabel.backgroundColor = [UIColor clearColor];
cameraLabel.font = [UIFont fontWithName:FONT_99FANGICON size:35];
[scrollView addSubview:cameraLabel];
[cameraLabel release];

这段代码展示一个相机图标

Demo

大家有兴趣的话,可以在项目中使用,IOS项目和Android项目都可以运用,十分方便,到此为止吧

解析IOS崩溃日志(crash Log)

  最近在解析umeng错误分析日志上有了重大突破!

  很显然,我们的应用免不了crash,各种各样的crash,不过大部分在提交至appstore前经过严格的“消毒”后,所剩无几了。but(这个词..)漏网之鱼总是有的嘛(貌似很多..囧)。好吧,看下文:

  首先看一些这些线上app crash 信息:

* Application received signal SIGSEGV
* Application received signal SIGBUS
* -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds for empty array
* -[JKArray objectAtIndex:]: index (0) beyond bounds (0)

SIGSEGV和SIGBUS一般是因为访问已被释放的内存或者调用不存在的方法导致的,余下两个就是数组越界的问题了 这些你都知道的,然后来看看具体的log信息:

Application received signal SIGSEGV

Application received signal SIGSEGV
(null)
(
0   CoreFoundation                      0x32f1c3ff  + 186
1   libobjc.A.dylib                     0x3ac17963 objc_exception_throw + 30
2   CoreFoundation                      0x32f1c307  + 106
3   appname                            0x14e1e1 appname + 1364449
4   libsystem_c.dylib                   0x3b08bd33 _sigtramp + 34
5   appname                            0x97525 appname + 615717
6   CoreFoundation                      0x32e6d349 _CFXNotificationPost + 1420
7   Foundation                          0x337879cd  + 168
8   Foundation                          0x337876c1  + 136
9   appname                            0x96f2f appname + 614191
10  Foundation                          0x33858915  + 16
11  Foundation                          0x33798769  + 200
12  Foundation                          0x33798685  + 60
13  CFNetwork                           0x32bf964f  + 26
14  CFNetwork                           0x32bf8d33  + 54
15  CFNetwork                           0x32c21013  + 18
16  CoreFoundation                      0x32e62acd CFArrayApplyFunction + 176
17  CFNetwork                           0x32c21473  + 74
18  CFNetwork                           0x32b85461  + 188
19  CoreFoundation                      0x32ef18f7  + 14
20  CoreFoundation                      0x32ef115d  + 212
21  CoreFoundation                      0x32eeff2f  + 646
22  CoreFoundation                      0x32e6323d CFRunLoopRunSpecific + 356
23  CoreFoundation                      0x32e630c9 CFRunLoopRunInMode + 104
24  GraphicsServices                    0x36a4233b GSEventRunModal + 74
25  UIKit                               0x34d7f2b9 UIApplicationMain + 1120
26  appname                            0xf3df appname + 58335
27  appname                            0x3578 appname + 9592
)

dSYM UUID: 365EF56E-D598-3B94-AD36-BFA13772A4E3
CPU Type: armv7s
Slide Address: 0x00001000
Binary Image: appname
Base Address: 0x000f7000

–[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds for empty array

*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds for empty array
(null)
(
0   CoreFoundation                      0x330dc3ff  + 186
1   libobjc.A.dylib                     0x3add7963 objc_exception_throw + 30
2   CoreFoundation                      0x33027ef9  + 164
3   appname                            0xcbcaf appname + 830639
4   appname                            0x40bc1 appname + 261057
5   appname                            0x3d297 appname + 246423
6   UIKit                               0x34f36569  + 408
7   UIKit                               0x34f1b391  + 1316
8   UIKit                               0x34f32827  + 206
9   UIKit                               0x34eee8c7  + 258
10  QuartzCore                          0x34c9a513  + 214
11  QuartzCore                          0x34c9a0b5  + 460
12  QuartzCore                          0x34c9afd9  + 16
13  QuartzCore                          0x34c9a9c3  + 238
14  QuartzCore                          0x34c9a7d5  + 316
15  QuartzCore                          0x34c9a639  + 60
16  CoreFoundation                      0x330b1941  + 20
17  CoreFoundation                      0x330afc39  + 276
18  CoreFoundation                      0x330aff93  + 746
19  CoreFoundation                      0x3302323d CFRunLoopRunSpecific + 356
20  CoreFoundation                      0x330230c9 CFRunLoopRunInMode + 104
21  GraphicsServices                    0x36c0233b GSEventRunModal + 74
22  UIKit                               0x34f3f2b9 UIApplicationMain + 1120
23  appname                            0xf3df appname + 58335
24  appname                            0x3578 appname + 9592
)

dSYM UUID: 365EF56E-D598-3B94-AD36-BFA13772A4E3
CPU Type: armv7s
Slide Address: 0x00001000
Binary Image: appname
Base Address: 0x000c3000

好了,相信你也看出来了,这些具体的crash log 什么都看不出来,都是一些内存地址,帧调用栈等,所以需要进一步的解析,看下文:

看一下上面的crash log,找到一句

5   appname                            0x97525 appname + 615717

它指出了应用名称,崩溃时的调用方法的地址,文件的地址以及方法所在的行的位置(具体请看这篇文章),接下来就要符号化(Symbolication)这句,用dwarfdump来检测crash log中dSYM UUID和本地的dSYM文件是否匹配

打开终端:

cd /Users/username/Library/Developer/Xcode/Archives/2013-08-30/app 8-30-13 6.19 PM.xcarchive/dSYMs
dwarfdump --uuid appname.app.dSYM
UUID: 9F0AEFA6-4349-30AF-8420-BCEE739DA0B4 (armv7) appname.app.dSYM/Contents/Resources/DWARF/appname
UUID: 365EF56E-D598-3B94-AD36-BFA13772A4E3 (armv7s) appname.app.dSYM/Contents/Resources/DWARF/appname

OK,crash log中的dSYM UUID与本地的dYSM文件是相匹配的。好接下来就查一下0x97525这个地址是什么,

dwarfdump --arch=armv7 --lookup 0x97525  /Users/username/Library/Developer/Xcode/Archives/2013-08-30/appname\ 8-30-13\ 6.19\ PM.xcarchive/dSYMs/appname.app.dSYM/Contents/Resources/DWARF/appname

得到的结果:

----------------------------------------------------------------------
File: /Users/username/Library/Developer/Xcode/  Archives/2013-08-30/appname 8-30-13 6.19    PM.xcarchive/dSYMs/appname.app.dSYM/Contents/   Resources/DWARF/appname (armv7)
----------------------------------------------------------------------
Looking up address: 0x0000000000097525 in .debug_info... found!

0x00359c67: Compile Unit: length = 0x000066f1  version = 0x0002  abbr_offset = 0x00000000  addr_size = 0x04  (next CU at 0x0036035c)

0x00359c72: TAG_compile_unit [1] *
         AT_producer( "Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)" )
         AT_language( DW_LANG_ObjC )
         AT_name( "xxx/EGOImageView.m" )
         AT_low_pc( 0x0009710c )
         AT_stmt_list( 0x000655c1 )
         AT_comp_dir( "xxx" )
         AT_APPLE_optimized( 0x01 )
         AT_APPLE_major_runtime_vers( 0x02 )

0x00359e57:     TAG_subprogram [10] *
             AT_name( "-[EGOImageView imageLoaderDidFailToLoad:]" )
             AT_decl_file( "xxx/EGOImageView.m" )
             AT_decl_line( 96 )
             AT_prototyped( 0x01 )
             AT_APPLE_isa( 0x01 )
             AT_low_pc( 0x00097490 )
             AT_high_pc( 0x00097572 )
             AT_frame_base( r7 )
             AT_object_pointer( {0x00359e6e} )
Line table dir : 'xxx'
Line table file: 'EGOImageView.m' line 99, column 2 with start address 0x00000000000974fe

Looking up address: 0x0000000000097525 in .debug_frame... found!

0x0000c620: FDE
    length: 0x0000000c
    CIE_pointer: 0x00000000
    start_addr: 0x00097490 -[EGOImageView imageLoaderDidFailToLoad:]
range_size: 0x000000e2 (end_addr = 0x00097572)
Instructions: 0x00097490: CFA=4294967295+4294967295

看一下结果:发现有AT_name、Line table dir :、Line table file:,aha!找到了出错的地方(出错的这个文件是网上别人写的,有bug,现已不再使用)。

注意:如果发现warning: unsupported file type:错误,这个问题是因为有文件或者目录的名称中包含空格,比如:2013-08-30/appname 8-30-13 6.19 ,所以,需要转义一下:2013-08-30/appname\ 8-30-13\ 6.19\ PM.xcarchive

参看此文章

OK,希望能有所帮助,到此为止吧

本博客的搭建

如果有人对git-hub + octopress的博客感兴趣的话,可以读一读下文:

1、首先读一下以下三个链接的文章

2、顺利的话,相信你已经搭建成功了,如果出了问题,可以看看下文,梳理一下:

  • git

    将git安装好,有git-hub的账号,对git做一些基本配置,比如:remote.origin.url = https://github.com/username/username.github.com.git , 这样git push origin source 才不会出错

  • 安装ruby和rvm

    记得安装好相关依赖项,如 bundle

  • 安装octopress

    生成博客或者是对octopress设置 都要记得 cd your_local_octopress_directory

其他配置

  • 添加音频

    下载[audio.js](http://kolber.github.io/audiojs/)
    将其中的audio.min.js和player-graphics.gif拷贝到/source/javascripts目录下
    编辑/source/_includes/head.html,加入如下代码:
    <script src="/javascripts/audio.min.js"></script>
    <script>
        audiojs.events.ready(function() {
        var as = audiojs.createAll();
        });
    </script>
    下载[Audio/MP3 Plugin for Octopress](https://gist.github.com/lieyunye/409b6c76f5d9dc4d7a5b)将其放在/plugins目录下
    最后编辑xxx.markdown 加入audio标签
    
  • 导航栏的配置

    cd source/_includes/custom
    <li><a href="/">首页</a></li>
    <li><a href="/blog/archives">所有文章</a></li>
    <li><a href="http://weibo.com/lieyunye" target="_blank">我的微博</a></li>
    
  • 关于我

    cd octopress/source/_includes/custom/asides
    <h1>About Me</h1>
    <p>爱帮网(2011---2012)<br/>
       九九房(2012---至今)</p>
    <br/>Java 开发工程师,曾开发爱帮生活、爱帮公交后台
    <br/>IOS 开发工程师,曾开发爱帮生活、掌上租房、找室友
    <br/>
    <br/>新浪微博:<a href='http://weibo.com/lieyunye' target='_blank'>裂云>野</a>
    </p>
    

    参见文档:http://octopress.org/docs/theme/template http://micronarrativ.org/blog/blog/2012/09/06/wordpress-til-octopress-audio/

OK,这就是本博客的搭建过程,到此为止吧

裂云野

裂云野是谁啊?