damien.h

Icecodez for iPhone

My friend Ryan and I just launched our team site Icecodez, which is dedicated to our iPhone apps development. The FIRST app by Icecodez just got out this week. Check out IceMetro Shahghai Subway Map Lite (itunes link). It’s an interactive map for Shanghai subway. And it’s free! Isn’t that ice cool?

Setting up MGTwitterEngine with YAJL 1.0.6 for iPhone development

*Corrected yajl include path. Updated info about adding YAJL static lib to project for deploying on device

MGTwitterEngine is a great Objective-C library for the Twitter API. Did you know the famous Twitterrific for iPhone (iTunes link) is built with MGTwitterEngine plus YAJL? You probably know that from the now famous YAJL error Twitterrific presented you when the Twitapocalypse hit the world, right?

But setting up MGTwitterEngine and YAJL for iPhone development turned out to be more difficult than I thought, due to the lack of documentation, and my lack of extensive experience with iPhone and Mac development. Anyway, after some hacking around, I finally got the two boys to play together and work with my next cool iPhone project. The following is how I did it and I think it might be useful to someone else wrestling with the same problem out there.

Getting and compiling YAJL on your Mac

First, get the latest YAJL code and get it compiled.

git clone git://github.com/lloyd/yajl

If you don’t have cmake on your Mac yet, get it via MacPorts. (The cmake version from Fink is too old to compile YAJL. I’ve tried it.)

sudo port install cmake

Now compile YAJL

cd yajl
sudo ./configure && make install

Now you should have “yajl-1.0.6” under the “build” folder. And the build process should have copied the binaries to /usr/local/lib/ and /usr/local/include/yajl respectively.

Getting MGTwitterEngine

Get the latest code from the SVN repo.

svn checkout http://svn.cocoasourcecode.com/MGTwitterEngine

Adding MGTwitterEngine to your iPhone project

Add everything from the MGTwitterEngine directory starting with “MGTwitter”, and also the NSString+UUID and NSData+Base64 category files, to the Xcode project. Choose to copy the files to the project.

Telling MGTwitterEngine to use YAJL

MGTwitterEngine doesn’t support Twitter’s search and trends API without YAJL, because these APIs only return JSON data. So obviously we need to tell MGTwitterEngine we have YAJL and please give us the support search and trends APIs, in addition to requesting JSON data for other Twitter API calls.

In MGTwitterEngineGlobalHeader.h

#define YAJL_AVAILABLE 1

Adding YAJL and LibXML to the project

Now add the required frameworks to the Xcode project.

Locate “/usr/local/lib/libyajl.dylib”, drag and drop it onto “Frameworks” in the Groups & Files pane in Xcode. Don’t choose to copy the files.

**BEGIN UPDATE**

Compiling YAJL from the source using the shipped makefile will produce the dynamic library binary files (yajl*.dylib) under /usr/local/lib. Although adding these files to the frameworks gets the project to compile and run on the simulator, this won’t work on a device since only static libraries are allowed on devices for third party frameworks.

Compiling the static library from the source code requires a bit more work but I found someone has already done that with more good stuff like an Obj-C wrapper for YAJL. So we can now simply grab this compiled YAJL static library for iPhone, exand it, then add the file “libYAJLIPhone.a” to the Frameworks.

**END UPDATE**

Then also add “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib/libxml2.dylib” to Frameworks.

Next, open Project Info, locate the Build page, and look for the “Header Search Paths” property. Add the following two paths to the search paths property.

/usr/local/include/yajl
$SDKROOT/usr/include/libxml2

*Although it seems LibXML is not required, I did get compilation errors if LibXML is not in the Frameworks.

Hack and get MGTwitterEngine to build

It appears that MGTwitterEngine is still written against a previous version of YAJL (supposedly a pre-1.0 version). So if at this stage you go ahead and build the project, you will see two errors from MGTwitterEngine.

error: too few arguments to function 'yajl_alloc'
error: too few arguments to function 'yajl_free_error'

It looks like the latest version of YAJL has changed its signatures of the functions “yajl_alloc” and “yajl_free_error”. So let’s hack the corresponding code in MGTwitterYAJLParser.m to work around the build errors. Find the calls to these two functions and change the code as follows.

...
_handle = yajl_alloc(&callbacks, &cfg, nil, self);
...
yajl_free_error(nil, errorMessage);
...

Done!

Now you can hit Build and the project should build successfully. Next, you should take a look at AppController.h and AppController.m which come with MGTwitterEngine and see how to use it. It’s pretty easy to use once you get past the compilation problems. Now we have a fully functional and nicely built Twitter library ready to be used for any iPhone project! Also, if you have any suggestion or any better way to get the stuff to work please let me know.

我最常用的XCode快捷键

和Xcode打了几个月的交道,总结一下我最常用也是最喜欢的几个快捷键。总的来说Xcode快捷键并不是非常丰富灵活,但熟悉了下面为数不多的几个快捷键以后工作效率马上可以提高不少。

  • Command-Option-Up: 切换.h和.m
  • Command-Shift-D: 快速打开文件
  • Control-2: 快速浏览当前文件成员
  • Alt-Command-Left/Right: 前一个/后一个编辑位置
  • Command-Shift-E: 最大化文件编辑区域
  • Control-/: 切换到下一个占位符(自动完成的时候)
  • Control-.: 下一个自动完成提示
  • Command-E: 使用当前选中内容查找
  • Command-G: 在当前文件中查找下一个
  • Command-Shift-F: 在项目中查找
  • Command-Alt-Shift-T: 在Groups&Files里定位到当前编辑的文件
  • Command+双击:浏览源文件
  • Alt+双击:查找帮助

外加一句,深感XCode一定要用All-In-One单窗口的Layout才好用。

    iPhone OS 3.0 beta初体验

    iPhone OS 3.0 beta发布后马上下载过来体验了一把,把自己的iPod Touch刷了3.0版firmware,也升级了XCode 3.1.3。这次大版本更新带来了非常多的新特性,iPhone离一台完美的手持设备已经非常非常近了。初步体验下来,3.0版OS的潜力还是要靠app来挖掘,系统的本来面目还没有特别大的区别,众多新特性需要有软件的支持才能用得到。普通用户一上手就能看到的改进主要是spotlight搜索,拷贝粘贴,还有开放的蓝牙(但是默认状态是什么蓝牙服务都没有的)。后台Push,in-app支付,turn-by-turn GPS等等重要特性都要等到众多新版应用出现以后才能体现出强大来。先上几张touch上的截图吧。

    我的Mac OS X开发环境设置

    我是一个Mac新手,算到现在只用了大概4个月的OS X。但是作为长期Linux用户,Mac的上手还是非常顺利的。作为一个开发者,我拿到心爱的Macbook Pro第一件事当然就是开始摸索让自己coding更舒服的环境了。折腾到现在算是小有成就,于是总结分享一下我在OS X下的开发环境设置。(商业软件用*标明)

    1. QuickSilver

    Linux下我用Gnome Do或者Launchy for Linux,Windows下我用Launchy,而QuickSilver才是大名鼎鼎的鼻祖。必备!

    2. Terminal.app

    Terminal是开发者最好的朋友。OS X的初始配置是非常弱化命令行功能的,所以需要根据自己的需要好好折腾一下。
    首先,默认settings我用的是pro,半透明黑色背景到哪里都是我的最爱。
    bash设置也需要按照我在Linux下的习惯调整一下。但是OS X和Linux不一样,默认不读取home下的.bashrc而是.profile。不想把.bashrc内容写到.profile里的话,就在.profile开头加上下面的脚本。

    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi
    

    然后把我Linux下的bash配置里适用的部分搬过来,保存为~/.bashrc。

    export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    alias ll='ls -l'
    alias la='ls -a'
    

    3. Visor

    Terminal的配置还没完,Visor是个必备物品。同为QuickSilver的制作公司出品,Visor是一个实现类似fps游戏屏幕顶部下拉命令行的Terminal插件。玩过Quake3的同学都明白这样的下拉式terminal有多爽多酷吧!我的Visor快捷键设成^F12,按下快捷键屏幕顶部的terminal呼之即来招之即去,非常过瘾。Linux下虽然也有Guake和Tilda,但是都比较buggy,还是Visor用得最爽。

    4. *TextMate

    TextMate是Mac下必备级别的开发利器。轻便的尺寸强大的功能,还有大量的Bundle资源,做绝大多数种类的开发都有很好的支持。我目前的TextMate配置是这样的。

    ProjectPlus插件

    TM必备,把一些经典IDE的功能带到了TM:用sidebar替换了TM的drawer,支持包括SVN和GIT的多种SCM集成,能直接把项目文件的SCM状态图标显示在文件图标上,支持color labels等等。装了ProjectPlus的TM在project中工作感觉会大不一样。

    GetBundles

    GetBundles和古老的GetBundle是两回事。GetBundles不光能从官方repository获取bundle,还能从github上拿到最新的bundle。用GetBundles安装bundle也异常方便,只需要指指点点就行了。真希望GetBundles能直接集成到TM2.0里。
    安装GetBundles需要用一下SVN,以后就一劳永逸了!

    cd ~/Library/Application\ Support/TextMate/Bundles
    svn co http://svn.textmate.org/trunk/Review/Bundles/GetBundles.tmbundle/
    

    然后到TM中Bundles>Bundle Editor>Reload Bundles,GetBundles Bundle就装好了。接下来就可以从菜单中选择Bundles>GetBundles>Get Bundles来查看所有可以安装的bundle了。
    另外,TM对中文和其他双字节字符显示支持有问题,可以用这款TM专用字体来解决。

    附加一个问题的解决方案。如果用了被黑名单了的d版序列号,TM打开了就会强制退出而没法重新输入序列号。这时候可以找到并打开 ~/Library/Preferences/com.macromates.textmate.plist文件,找到“OakSoftwareRegistrationOwner”和“OakSoftwareRegistrationSerialNumber”两项并把值清空就能清除序列号重新进入TM了。

    5. *Path Finder

    Path Finder是款强大的用来替换Finder的文件管理器。可以新建文件(这个很重要,不是吗?),分tab浏览,更好的路径导航,并排窗口浏览,自定义功能的抽屉等等,强大的不得了。必备级别,用了才知道原来用Finder是多么痛苦!

    6. Fink

    装了Fink,就能用熟悉的sudo apt-get了。

    7. 其他

    系统状态监控:iStat Menus和iStat Pro
    风扇调速:smcFanControl
    还有MacVim
    另外,用惯了Ubuntu下的Compiz Fusion,感觉OS X的Spaces还是弱了点,不过总比没有好。窗口太多的时候分门别类到不同的space下去就清爽多了。

    基本上必须的部分就是这么多了。欢迎补充!

    Google Quick Search Bar

    作为Google Mac Team的一员,Mac必备工具QuickSilver的作者Nicholas Jitkoff发布了Google Quick Search Bar for Mac!话说QuickSilver很久没什么动静了,原来Nicholas忙这个呢。
    马上在我的mbp上装上开始用了,毕竟是同一个作者,QSB深得QS的精髓,但又不和QS功能上重叠太多。值得一提的是集成Spotlight的功能,这点用起来很爽,只是目前的早期版本打开Spotlight集成以后性能就下降了,用了半天碰到几次CPU占满的情况。另外方面,和Google服务的集成(Search, GCal, GMail),输入计算表达式直接给出结果等功能也非常使用,也是QS欠缺的,这些功能倒是让我想起Win/Linux上的Launchy了。
    虽然目前的版本还支持早期原型,但是绝对值得Mac上的敲键盘爱好者们期待!现在其我就QS和QSB双管齐下了。对了,还有FF下的Ubiquity等着我呢。

    Quick Search Bar

    Quick Search Bar

    Browse Happy logo

    My tweets

    2016年七月
    « 八    
     123
    45678910
    11121314151617
    18192021222324
    25262728293031

    分类目录

    Articles

    Fancy Stats