<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>以太之内 生存之上 &#187; Coding</title> <atom:link href="http://ixhan.com/category/coding/feed/" rel="self" type="application/rss+xml" /><link>http://ixhan.com</link> <description>Live in your world, get owned in mine</description> <lastBuildDate>Fri, 03 Feb 2012 02:58:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>ObjC中URL编码</title><link>http://ixhan.com/2011/09/objective-c-url-encoding/</link> <comments>http://ixhan.com/2011/09/objective-c-url-encoding/#comments</comments> <pubDate>Thu, 29 Sep 2011 10:30:00 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[NSString]]></category> <category><![CDATA[URL encoding]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=638</guid> <description><![CDATA[<a
href="http://ixhan.com/2011/09/objective-c-url-encoding/" title="ObjC中URL编码"></a>NSString类已经中提供了现成的API： 但是非常重要的一点苹果没注明：该API并不会将&#8221;&#38; + -&#8221;等需要转义的字符编码。 如若将需要传递的某个param的内容通过该API来转义就可能坑爹了！！你内容中的&#38;=不会被转义，服务端就会把原来的内容根据&#38;和=拆开成一片一片了！！ 解决方法是使用介绍中提到的CFURLCreateStringByAddingPercentEscapes 需要注意的是不能将这个函数用来 encode 整个URL，而是params的内容 &#8212; 写这篇文章是因为自己也掉了这个大坑，而且半年后才注意到。惨吖，不知道收集的10多w条数据中有多少是内容破坏的 &#8211; - Related PostsRead UTF8 code at specify position from an NSString]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2011/09/objective-c-url-encoding/" title="ObjC中URL编码"></a><p>NSString类已经中提供了现成的API：</p><pre class="brush: objc; title: ; notranslate">
/* Adds all percent escapes necessary to convert the receiver in to a legal URL string.
  Uses the given encoding to determine the correct percent escapes (returning nil if
the given encoding cannot encode a particular character).  See
CFURLCreateStringByAddingPercentEscapes in CFURL.h for more complex transformations
*/
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc;
</pre><p>但是非常重要的一点苹果没注明：该API并不会将&#8221;&amp; + -&#8221;等需要转义的字符编码。<br
/> 如若将需要传递的某个param的内容通过该API来转义就可能坑爹了！！你内容中的&amp;=不会被转义，服务端就会把原来的内容根据&amp;和=拆开成一片一片了！！</p><p>解决方法是使用介绍中提到的CFURLCreateStringByAddingPercentEscapes</p><pre class="brush: objc; title: ; notranslate">
@implementation NSString (URLEscaped)
- (NSString *)URLEscaped {
	CFStringRef escaped = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@&quot;!*'();:@&amp;=+$,/?%#[]&quot;,
			 kCFStringEncodingUTF8);
	NSString *out = [NSString stringWithString:(NSString *)escaped];
	CFRelease(escaped);
	return [[out copy] autorelease];
}
</pre><p>需要注意的是不能将这个函数用来 encode 整个URL，而是params的内容</p><p>&#8212;<br
/> 写这篇文章是因为自己也掉了这个大坑，而且半年后才注意到。惨吖，不知道收集的10多w条数据中有多少是内容破坏的 &#8211; -</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/" title="Read UTF8 code at specify position from an NSString">Read UTF8 code at specify position from an NSString</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2011/09/objective-c-url-encoding/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>LessLyrics 重启</title><link>http://ixhan.com/2011/09/lesslyrics-relaunch-now/</link> <comments>http://ixhan.com/2011/09/lesslyrics-relaunch-now/#comments</comments> <pubDate>Wed, 21 Sep 2011 15:00:03 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Project]]></category> <category><![CDATA[LessLyrics]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=621</guid> <description><![CDATA[<a
href="http://ixhan.com/2011/09/lesslyrics-relaunch-now/" title="LessLyrics 重启"></a>原谅4月份时候的大放厥词 &#8220;LessLyrics歌词秀后续计划&#8221; 今天写这文章时才发现居然又过去了5个月。这几个月里辞去了百度的工作，和朋友们开始了全新的创业之路，断断续续的也就选择性的忘记了这个升级计划。 当然还有2个原因，计划的0.8版本中无缝滚动动画效果依赖非常精确的iTunes播放时间，但是能取到最小的间隔是1秒，所以处理起一些细节会比较麻烦。但是呢从当时的预览视频可以看到其实当时完成度已经很高了，在我开心的向datou炫耀这个超级华丽无缝歌词滚动动画效果，结果datou研究了很久后，说了句。不好。 虽然不愿意承认这么帅气的效果被否决，但仔细想确实有很大的问题。无缝滚动效果会导致整个界面一直处于动画中，当前高亮播放中的歌词也一直在逐渐向上滚动，会导致使用者为了fo这行歌词一直让眼球向上扫描，接着目光聚集到下面的歌词，然后又继续向上扫。看久了就会觉得挺累。 昨天在我们的app内测qq群中有用户问要显示歌词的软件。我赶紧推荐了LessLyrics，结果人家居然说，居然说，说：“这个app早就知道了！！我想要iPhone版本的” 于是我爽到现在，于是决定必须立刻重新启动LessLyrics软件计划了！ 新的0.8版本没增加太多的功能，因为迫不及待要发布新版本收集下反馈。这次完全重写了app的设计结构和渲染模块（现在看1年前刚学习mac开发的代码真的很戳），接下来的添加新功能就方便了。 不用期待，几小时内发布。 哈哈哈哈哈哈哈哈哈哈哈哈哈哈。 下载请移步至 项目页面 Related PostsLyrics Tutorial for LyricStreamLessLyrics 歌词秀后续计划LessLyrics]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2011/09/lesslyrics-relaunch-now/" title="LessLyrics 重启"></a><p>原谅4月份时候的大放厥词 &#8220;<a
href="http://ixhan.com/2011/04/plans-for-lesslyrics/">LessLyrics歌词秀后续计划</a>&#8221;</p><p>今天写这文章时才发现居然又过去了5个月。这几个月里辞去了百度的工作，和朋友们开始了全新的创业之路，断断续续的也就选择性的忘记了这个升级计划。</p><p>当然还有2个原因，计划的0.8版本中无缝滚动动画效果依赖非常精确的iTunes播放时间，但是能取到最小的间隔是1秒，所以处理起一些细节会比较麻烦。但是呢从当时的预览视频可以看到其实当时完成度已经很高了，在我开心的向datou炫耀这个超级华丽无缝歌词滚动动画效果，结果datou研究了很久后，说了句。不好。</p><p>虽然不愿意承认这么帅气的效果被否决，但仔细想确实有很大的问题。无缝滚动效果会导致整个界面一直处于动画中，当前高亮播放中的歌词也一直在逐渐向上滚动，会导致使用者为了fo这行歌词一直让眼球向上扫描，接着目光聚集到下面的歌词，然后又继续向上扫。看久了就会觉得挺累。</p><p>昨天在我们的app内测qq群中有用户问要显示歌词的软件。我赶紧推荐了LessLyrics，结果人家居然说，居然说，说：“这个app早就知道了！！我想要iPhone版本的”</p><p>于是我爽到现在，于是决定必须立刻重新启动LessLyrics软件计划了！</p><p>新的0.8版本没增加太多的功能，因为迫不及待要发布新版本收集下反馈。这次完全重写了app的设计结构和渲染模块（现在看1年前刚学习mac开发的代码真的很戳），接下来的添加新功能就方便了。</p><p>不用期待，几小时内发布。</p><p>哈哈哈哈哈哈哈哈哈哈哈哈哈哈。</p><p>下载请移步至 <a
target="_blank" title="LessLyrics" href="/lesslyrics/" target="_blank">项目页面</a></p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/lesslyrics/download-lyrics-tutorial/" title="Lyrics Tutorial for LyricStream">Lyrics Tutorial for LyricStream</a></li><li><a
href="http://ixhan.com/2011/04/plans-for-lesslyrics/" title="LessLyrics 歌词秀后续计划">LessLyrics 歌词秀后续计划</a></li><li><a
href="http://ixhan.com/lesslyrics/" title="LessLyrics">LessLyrics</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2011/09/lesslyrics-relaunch-now/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>CrazyText &#8211; My First MacRuby App</title><link>http://ixhan.com/2011/04/crazytext-my-first-macruby-app/</link> <comments>http://ixhan.com/2011/04/crazytext-my-first-macruby-app/#comments</comments> <pubDate>Mon, 18 Apr 2011 15:05:54 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Project]]></category> <category><![CDATA[crazy text]]></category> <category><![CDATA[MacRuby]]></category> <category><![CDATA[opensource]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=539</guid> <description><![CDATA[<a
href="http://ixhan.com/2011/04/crazytext-my-first-macruby-app/" title="CrazyText - My First MacRuby App"><img
width="320" height="200" src="http://ixhan.com/wp-content/uploads/2011/04/crazy_text_screenshot.jpg" class="attachment-extra-featured-image wp-post-image" alt="Crazy Text screenshot" title="Crazy Text screenshot" /></a>前不久听说MacRuby 0.10 发布,并支持了Mac App Store 的发布. 于是边学习Ruby边学习MacRuby边学习cocoa 写了这么一个东西. A MacOSX app written in Macruby to create some funny  effects for your texts. 提交时候提示MacRuby.framework内的几个link位置不对. 忘记什么提示了,需要手动修复几个link文件的地址. 对了1 :源码请移步 github-&#62; https://github.com/xhan/CrazyText 对了2: 可以在appstore下载哦 部分UI仍然使用 objc编写(有些类和方法实在不知道如何用ruby实现) 个人感觉macruby 的学习曲线还真蛮高的,会cocoa,会ruby,还得会MacRuby,非常坑人,而且调试也非常又难度. Related Posts开源项目 LessDJ &#8211; 简约至上的音乐电台DJ永远的扫雷英雄(开源) 登场PlutoCMS! 基于ROR的内容管理系统[iPhone]播放midi文件]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2011/04/crazytext-my-first-macruby-app/" title="CrazyText - My First MacRuby App"><img
width="320" height="200" src="http://ixhan.com/wp-content/uploads/2011/04/crazy_text_screenshot.jpg" class="attachment-extra-featured-image wp-post-image" alt="Crazy Text screenshot" title="Crazy Text screenshot" /></a><p>前不久听说MacRuby 0.10 发布,并支持了Mac App Store 的发布.</p><p>于是边学习Ruby边学习MacRuby边学习cocoa 写了这么一个东西.</p><p>A MacOSX app written in Macruby to create some funny  effects for your texts.</p><p><a
href="http://ixhan.com/wp-content/uploads/2011/04/crazy_text_screenshot1.jpg"><img
class="alignnone size-full wp-image-543" title="Crazy Text" src="http://ixhan.com/wp-content/uploads/2011/04/crazy_text_screenshot1.jpg" alt="" width="576" height="360" /></a></p><p>提交时候提示MacRuby.framework内的几个link位置不对. 忘记什么提示了,需要手动修复几个link文件的地址.</p><p>对了1 :源码请移步 github-&gt; <a
target="_blank" href="https://github.com/xhan/CrazyText" target="_blank">https://github.com/xhan/CrazyText</a></p><p>对了2:</p><p><a
target="_blank" href="http://itunes.apple.com/us/app/crazy-text/id431122700?mt=12"><img
class="alignnone" title="mac app store" src="https://developer.apple.com/appstore/images/available-on-mac-app-store.png" alt="" width="160" height="48" /></a> 可以在<a
target="_blank" href="http://itunes.apple.com/us/app/crazy-text/id431122700?mt=12" target="_blank">appstore</a>下载哦</p><p>部分UI仍然使用 objc编写(有些类和方法实在不知道如何用ruby实现)</p><p>个人感觉macruby 的学习曲线还真蛮高的,会cocoa,会ruby,还得会MacRuby,非常坑人,而且调试也非常又难度.</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2012/01/opensource-lessdj/" title="开源项目 LessDJ &#8211; 简约至上的音乐电台DJ">开源项目 LessDJ &#8211; 简约至上的音乐电台DJ</a></li><li><a
href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a
href="http://ixhan.com/2009/10/plutocms-ruby-on-rails-cms/" title="PlutoCMS! 基于ROR的内容管理系统">PlutoCMS! 基于ROR的内容管理系统</a></li><li><a
href="http://ixhan.com/2009/10/how-to-let-iphone-play-midi-file/" title="[iPhone]播放midi文件">[iPhone]播放midi文件</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2011/04/crazytext-my-first-macruby-app/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>UIViewController 的内存管理</title><link>http://ixhan.com/2011/02/uiviewcontroller-memory-manage/</link> <comments>http://ixhan.com/2011/02/uiviewcontroller-memory-manage/#comments</comments> <pubDate>Mon, 28 Feb 2011 15:24:30 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[iOS]]></category> <category><![CDATA[memory manage]]></category> <category><![CDATA[UIViewController]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=503</guid> <description><![CDATA[<a
href="http://ixhan.com/2011/02/uiviewcontroller-memory-manage/" title="UIViewController 的内存管理"></a>在iOS3.0后,UIViewController多了一个叫做viewDidUnLoad的方法.不少人都不清楚这个方法的具体意义,苹果的文档也就一句&#8221;Called when the controller’s view is released from memory&#8221;　简单的解释了下,并要求你把IBOutlet绑定的视图给清空,为什么呢? 先看下UIViewController从创建view到展示的流程的几个函数 -init -initWithNibName:bundle: 这两个方法都是初始化一个vc,但请注意view不是这时候载入的 -loadView -viewDidLoad 当一个视图准备展现时,vc首先会判断view是否已经创建,否则便通过之前指定的xib文件来初始化view,以及绑定其他关系(若没有指定xib文件,则默认会搜索和vc同名的xib,比如myNameViewController就会搜索 myNameViewController.xib文件) 若是没有xib文件,你就可以在loadview中自己手动创建这个viewControoler需要的视图. 接下来就是调用到 -viewDidLoad,许多人喜欢在这里做些其他事情,比如做个http请求,建立个数组啥的, 这里若不处理正确,　-viewDidUnload 激活时内存就容易泄露了,稍后提到. -view()appear -view()disappear 这几个方法就不解释了 -viewDidUnload 该方法在收到内存警告,同时该视图并不在当前界面显示时候会被调用,此时该controller的view已经被释放并赋值为nil. 接下来你要做的是 把实例变量的子视图释放(IBOulet的,以及自己添加的),. 其他实例变量,比如之前在-viewDidLoaded中实例的数据数组,http请求释放掉. 因为当该viewController再次被激活准备显示时(比如navigationControler返回到上一级),vc发现自己的view为空后会重复之前的流程直到把view给创建起来,若没将自己额外添加的子视图,各种类实例变量释放,这里便会重新再次创建. 于是,内存泄露了. Related PostsUITableView 离奇滚动到顶部的问题]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2011/02/uiviewcontroller-memory-manage/" title="UIViewController 的内存管理"></a><p>在iOS3.0后,UIViewController多了一个叫做viewDidUnLoad的方法.不少人都不清楚这个方法的具体意义,苹果的文档也就一句&#8221;Called when the controller’s view is released from memory&#8221;　简单的解释了下,并要求你把IBOutlet绑定的视图给清空,为什么呢?</p><p>先看下UIViewController从创建view到展示的流程的几个函数</p><blockquote><p>-init<br
/> -initWithNibName:bundle:</p></blockquote><p>这两个方法都是初始化一个vc,但请注意view不是这时候载入的</p><blockquote><p>-loadView<br
/> -viewDidLoad</p></blockquote><p>当一个视图准备展现时,vc首先会判断view是否已经创建,否则便通过之前指定的xib文件来初始化view,以及绑定其他关系(若没有指定xib文件,则默认会搜索和vc同名的xib,比如myNameViewController就会搜索 myNameViewController.xib文件)</p><p>若是没有xib文件,你就可以在loadview中自己手动创建这个viewControoler需要的视图.<br
/> 接下来就是调用到 -viewDidLoad,许多人喜欢在这里做些其他事情,比如做个http请求,建立个数组啥的, 这里若不处理正确,　-viewDidUnload 激活时内存就容易泄露了,稍后提到.</p><blockquote><p>-view()appear<br
/> -view()disappear</p></blockquote><p>这几个方法就不解释了</p><blockquote><p>-viewDidUnload</p></blockquote><p>该方法在收到内存警告,同时该视图并不在当前界面显示时候会被调用,此时该controller的view已经被释放并赋值为nil.<br
/> 接下来你要做的是</p><ol><li>把实例变量的子视图释放(IBOulet的,以及自己添加的),.</li><li>其他实例变量,比如之前在-viewDidLoaded中实例的数据数组,http请求释放掉.</li></ol><p>因为当该viewController再次被激活准备显示时(比如navigationControler返回到上一级),vc发现自己的view为空后会重复之前的流程直到把view给创建起来,若没将自己额外添加的子视图,各种类实例变量释放,这里便会重新再次创建.</p><p>于是,内存泄露了.</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2011/09/uitableview-offset-to-top-unexpected/" title="UITableView 离奇滚动到顶部的问题">UITableView 离奇滚动到顶部的问题</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2011/02/uiviewcontroller-memory-manage/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Read UTF8 code at specify position from an NSString</title><link>http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/</link> <comments>http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/#comments</comments> <pubDate>Thu, 24 Feb 2011 14:19:48 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[字符编码]]></category> <category><![CDATA[NSString]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=493</guid> <description><![CDATA[<a
href="http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/" title="Read UTF8 code at specify position from an NSString"></a>如何获取nsstring制定某个位置的utf８编码的字符呢? 我也不知道,所以在stackoverflow问了下. 很快就有人回复了解决方案. 在贴代码之前写介绍下几个编码格式: UTF8 和 UTF16均为字符编码方式. UTF-8使用一至四個位元組為每個字符編碼： 128個US-ASCII字符只需一個位元組編碼（Unicode範圍由U+0000至U+007F）。 帶有附加符号的拉丁文、希臘文、西里爾字母、亞美尼亞語、希伯來文、阿拉伯文、敘利亞文及它拿字母則需要二個位元組編碼（Unicode範圍由U+0080至U+07FF）。 其他基本多文種平面（BMP）中的字元（這包含了大部分常用字）使用三個位元組編碼。 其他極少使用的Unicode 輔助平面的字元使用四位元組編碼。 UTF-16是Unicode的其中一個使用方式。UTF是Unicode/UCS Transformation Format，即把Unicode轉做某種格式的意思。 其編碼方法是： 1如果字符編碼U小於0&#215;10000，也就是十進制的0到65535之內，則直接使用兩字節表示； 2如果字符編碼U大於0&#215;10000，由於UNICODE編碼範圍最大為0x10FFFF，從0&#215;10000到0x10FFFF之間 共有0xFFFFF個編碼，也就是需要20個bit就可以標示這些編碼。用U&#8217;表示從0-0xFFFFF之間的值，將其前 10 bit作為高位和16 bit的數值0xD800進行 邏輯or 操作，將後10 bit作為低位和0xDC00做 邏輯or 操作，這樣組成的 4個byte就構成了U的編碼。 而NSString使用的就是unicode存储的,　唯一一个获取unichar的方法叫做 -characterAtIndex: ,　但是问题是 unichar 其实是个 unsigned short,也就是２个字节,所以它并不能展现所有的字符. 终极解决方法: Related PostsObjC中URL编码]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/" title="Read UTF8 code at specify position from an NSString"></a><p>如何获取nsstring制定某个位置的utf８编码的字符呢?</p><p>我也不知道,所以在<a
target="_blank" href="http://stackoverflow.com/questions/5100030/read-utf8-character-in-specify-position-from-a-nsstring">stackoverflow</a>问了下.</p><p>很快就有人回复了解决方案.</p><p>在贴代码之前写介绍下几个编码格式:</p><p>UTF8 和 UTF16均为字符编码方式.</p><p>UTF-8使用一至四個<a
target="_blank" title="字节" href="http://zh.wikipedia.org/wiki/%E5%AD%97%E8%8A%82">位元組</a>為每個字符編碼：</p><ol><li>128個US-ASCII字符只需一個位元組編碼（Unicode範圍由U+0000至U+007F）。</li><li>帶有<a
target="_blank" href="http://zh.wikipedia.org/wiki/%E9%99%84%E5%8A%A0%E7%AC%A6%E5%8F%B7">附加符号</a>的<a
target="_blank" title="拉丁文" href="http://zh.wikipedia.org/wiki/%E6%8B%89%E4%B8%81%E6%96%87">拉丁文</a>、<a
target="_blank" title="希臘文" href="http://zh.wikipedia.org/wiki/%E5%B8%8C%E8%87%98%E6%96%87">希臘文</a>、<a
target="_blank" title="西里爾字母" href="http://zh.wikipedia.org/wiki/%E8%A5%BF%E9%87%8C%E7%88%BE%E5%AD%97%E6%AF%8D">西里爾字母</a>、<a
target="_blank" title="亞美尼亞語" href="http://zh.wikipedia.org/wiki/%E4%BA%9E%E7%BE%8E%E5%B0%BC%E4%BA%9E%E8%AA%9E">亞美尼亞語</a>、<a
target="_blank" title="希伯來文" href="http://zh.wikipedia.org/wiki/%E5%B8%8C%E4%BC%AF%E4%BE%86%E6%96%87">希伯來文</a>、<a
target="_blank" title="阿拉伯文" href="http://zh.wikipedia.org/wiki/%E9%98%BF%E6%8B%89%E4%BC%AF%E6%96%87">阿拉伯文</a>、<a
target="_blank" title="叙利亚文" href="http://zh.wikipedia.org/wiki/%E5%8F%99%E5%88%A9%E4%BA%9A%E6%96%87">敘利亞文</a>及<a
target="_blank" href="http://zh.wikipedia.org/wiki/%E5%AE%83%E6%8B%BF%E5%AD%97%E6%AF%8D">它拿字母</a>則需要二個位元組編碼（Unicode範圍由U+0080至U+07FF）。</li><li>其他<a
target="_blank" href="http://zh.wikipedia.org/wiki/%E5%9F%BA%E6%9C%AC%E5%A4%9A%E6%96%87%E7%A8%AE%E5%B9%B3%E9%9D%A2">基本多文種平面</a>（BMP）中的字元（這包含了大部分常用字）使用三個位元組編碼。</li><li>其他極少使用的Unicode <a
target="_blank" title="輔助平面" href="http://zh.wikipedia.org/wiki/%E8%BC%94%E5%8A%A9%E5%B9%B3%E9%9D%A2">輔助平面</a>的字元使用四位元組編碼。</li></ol><p><strong>UTF-16</strong>是<a
target="_blank" href="http://zh.wikipedia.org/wiki/Unicode">Unicode</a>的其中一個使用方式。UTF是<em>Unicode/UCS Transformation Format</em>，即把Unicode轉做某種格式的意思。</p><p>其編碼方法是：</p><p>1如果字符編碼U小於0&#215;10000，也就是十進制的0到65535之內，則直接使用兩字節表示；</p><p>2如果字符編碼U大於0&#215;10000，由於UNICODE編碼範圍最大為0x10FFFF，從0&#215;10000到0x10FFFF之間 共有0xFFFFF個編碼，也就是需要20個bit就可以標示這些編碼。用U&#8217;表示從0-0xFFFFF之間的值，將其前 10 bit作為高位和16 bit的數值0xD800進行 邏輯or 操作，將後10 bit作為低位和0xDC00做 邏輯or 操作，這樣組成的 4個byte就構成了U的編碼。</p><p>而NSString使用的就是unicode存储的,　唯一一个获取unichar的方法叫做 -characterAtIndex: ,　但是问题是 unichar 其实是个 unsigned short,也就是２个字节,所以它并不能展现所有的字符.</p><p>终极解决方法:</p><pre>
<pre class="brush: objc; title: ; notranslate">
@interface NSString (UTF8)
- (NSRange) rangeOfUTFCodePoint:(NSUInteger)number;
@end
@implementation NSString (UTF8)
- (NSRange) rangeOfUTFCodePoint:(NSUInteger)number
{
    if (number &gt;= [self length]) {
        return NSMakeRange(NSNotFound, NSNotFound);
    }
    NSUInteger codeUnit = 0;
    NSRange result;
    for(NSUInteger ix = 0; ix &lt;= number; ix++)
    {
        result = [self rangeOfComposedCharacterSequenceAtIndex:codeUnit];
        codeUnit += result.length;
    }
    return result;
}
@end
</pre></pre><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2011/09/objective-c-url-encoding/" title="ObjC中URL编码">ObjC中URL编码</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2011/02/read-utf8-code-at-specify-position-from-an-nsstring/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>关于豆瓣电台osx版</title><link>http://ixhan.com/2010/07/about-douban-radio-osx/</link> <comments>http://ixhan.com/2010/07/about-douban-radio-osx/#comments</comments> <pubDate>Sat, 10 Jul 2010 07:36:47 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[douban]]></category> <category><![CDATA[mac]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=370</guid> <description><![CDATA[<a
href="http://ixhan.com/2010/07/about-douban-radio-osx/" title="关于豆瓣电台osx版"></a>突发奇想为什么不做个豆瓣电台的osx版本呢 于是就有了这个开源的项目 http://ixhan.com/project/douban-fm-osx/ 后发现Du Song同学的FanRadio: Free Music For Mac 已做的无懈可击，同时twitter上朋友告诉我dashboard已经支持后台的音乐播放了。 有点多此一举的感觉。= = 不过个人还是喜欢一个原生的播放器浮在桌面上的感觉拉。 原计划0.2版本中会提供解析当前歌手名，歌曲名并可以同步更新至adium的状态，以及歌词显示功能。 坏消息是今天发现从flash中获取到内容相当困难。 好消息是通过抓包发现了豆瓣电台的接口，相当简单。可以做不少好玩的东西去。 Related Posts[Mac]终端中快速定位到Finder的当前路径Mac可以这么玩-用Finder示爱!使用Hamachi和Screen Share远程管理你的MacLessLyrics]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2010/07/about-douban-radio-osx/" title="关于豆瓣电台osx版"></a><p>突发奇想为什么不做个豆瓣电台的osx版本呢</p><p>于是就有了这个开源的项目 <a
href="http://ixhan.com/project/douban-fm-osx/">http://ixhan.com/project/douban-fm-osx/</a></p><p>后发现<cite><a
target="_blank" rel="external nofollow" href="http://blog.rollingcode.org/">Du  Song</a></cite>同学的<a
target="_blank" rel="bookmark" href="http://blog.rollingcode.org/2010/06/20/fanradio-1/">FanRadio:  Free Music For Mac </a>已做的无懈可击，同时twitter上朋友告诉我dashboard已经支持后台的音乐播放了。</p><p>有点多此一举的感觉。= =</p><p>不过个人还是喜欢一个原生的播放器浮在桌面上的感觉拉。</p><p>原计划0.2版本中会提供解析当前歌手名，歌曲名并可以同步更新至adium的状态，以及歌词显示功能。</p><p>坏消息是今天发现从flash中获取到内容相当困难。</p><p>好消息是通过抓包发现了豆瓣电台的接口，相当简单。可以做不少好玩的东西去。</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2011/12/terminal-fast-switch-dir-to-finder-current-dictionar/" title="[Mac]终端中快速定位到Finder的当前路径">[Mac]终端中快速定位到Finder的当前路径</a></li><li><a
href="http://ixhan.com/2011/04/declaring-love-with-macosx-finder/" title="Mac可以这么玩-用Finder示爱!">Mac可以这么玩-用Finder示爱!</a></li><li><a
href="http://ixhan.com/2011/03/using-hamachi-to-remote-control-macs-anywhere/" title="使用Hamachi和Screen Share远程管理你的Mac">使用Hamachi和Screen Share远程管理你的Mac</a></li><li><a
href="http://ixhan.com/lesslyrics/" title="LessLyrics">LessLyrics</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2010/07/about-douban-radio-osx/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>栽大了之Objc过度释放对象</title><link>http://ixhan.com/2009/11/shit-on-objc-object-manager/</link> <comments>http://ixhan.com/2009/11/shit-on-objc-object-manager/#comments</comments> <pubDate>Thu, 26 Nov 2009 09:37:28 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[iOS]]></category> <category><![CDATA[apple]]></category> <category><![CDATA[决定]]></category> <category><![CDATA[内存管理]]></category> <category><![CDATA[c]]></category> <category><![CDATA[objective-c]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=196</guid> <description><![CDATA[<a
href="http://ixhan.com/2009/11/shit-on-objc-object-manager/" title="栽大了之Objc过度释放对象"></a>事情是这样的,4个月前我写了份实现类似下拉框选择操作的界面. 一个月前,发现了这个View 在dealloc 会crash掉. 多次调试无果,上 devForum.apple.com 询问也无人问津. 今天决定再次调试下,还是没找到哪里出问题. 最后决定求助 cocoachina 上的现场观众 最后开始一行一行的注释代码做终极调试. 离谱的事情发现了,只要我创建一个名为 mainText 的 UILabel ,在dealloc 中程序就会crash ,改成其他名字无事.难道是apple的bug? 新写了个view测试了,还是没问题. 接着接着就发现了在dealloc方法中: [mainText release] ,mainText = nil; // NSLog(@"release %@",bgView); [bgView release]; // NSLog(@"release %@",originView); [originView release]; // NSLog(@"release %@",labelArray); [labelArray &#8230;<p
class="read-more"><a
href="http://ixhan.com/2009/11/shit-on-objc-object-manager/">Read more &#187;</a></p>]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2009/11/shit-on-objc-object-manager/" title="栽大了之Objc过度释放对象"></a><p>事情是这样的,4个月前我写了份实现类似下拉框选择操作的界面.<br
/> 一个月前,发现了这个View 在dealloc 会crash掉.<br
/> 多次调试无果,上 devForum.apple.com 询问也无人问津.<br
/> 今天决定再次调试下,还是没找到哪里出问题.<br
/> 最后决定求助 cocoachina 上的现场观众<br
/> 最后开始一行一行的注释代码做终极调试.</p><p>离谱的事情发现了,只要我创建一个名为 mainText 的 UILabel ,在dealloc 中程序就会crash ,改成其他名字无事.难道是apple的bug? 新写了个view测试了,还是没问题.</p><p>接着接着就发现了在dealloc方法中:<br
/> <code> [mainText release] ,mainText = nil;<br
/> //	NSLog(@"release %@",bgView);<br
/> [bgView release];<br
/> //	NSLog(@"release %@",originView);<br
/> [originView release];<br
/> //	NSLog(@"release %@",labelArray);<br
/> [labelArray release];<br
/> //	NSLog(@"release %@",mainText);<br
/> [mainText release];<br
/> </code><br
/> 该死的,不知道当时那根神经错了,居然释放了两次,当然出错咯.问题也解决了.</p><p>所以在确认释放对象的情况下一定要写成:<br
/> [instance release],instance = nil ;</p><p>个人经验是,对于objective-c的内存管理都是得经过磨练才出来的,前期多犯错误是好事情.<br
/> 当然我认识一个朋友 ,他不释放任何对象,因为反正关闭iPhone后系统会处理的.这种觉悟不是大部分程序员有的,大家还是稳步前进咯.</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a
href="http://ixhan.com/2010/04/apple-such-a-bitch/" title="Apple 发疯了">Apple 发疯了</a></li><li><a
href="http://ixhan.com/2009/12/dec-review/" title="12月串烧-年轻人就要飘逸">12月串烧-年轻人就要飘逸</a></li><li><a
href="http://ixhan.com/2009/11/things-ive-done-in-past-5-months/" title="Things I&#8217;ve done int past 5 months">Things I&#8217;ve done int past 5 months</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2009/11/shit-on-objc-object-manager/feed/</wfw:commentRss> <slash:comments>145</slash:comments> </item> <item><title>游戏开发牛书推荐</title><link>http://ixhan.com/2009/11/yoooo/</link> <comments>http://ixhan.com/2009/11/yoooo/#comments</comments> <pubDate>Tue, 24 Nov 2009 16:45:21 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[c]]></category> <category><![CDATA[game]]></category> <category><![CDATA[objective-c]]></category> <category><![CDATA[游戏开发]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=194</guid> <description><![CDATA[<a
href="http://ixhan.com/2009/11/yoooo/" title="游戏开发牛书推荐"></a>在看一本叫 Programming Game AI By Examples 的书 （本来打算买实体书的，后来想想不能破例，还是down了本电子书 &#8220;） 看完第二章后彻底折服了 ，写的这么好的书真是不多见的 这才是真正的设计模式 ，寥寥几行代码就把整个世界给建模了 结构异常清晰，细节异常周到 堪称完美的作品 自己曾设计了不少不成型的东西，这次能见大师级别的代码确实收获颇多。 觉得一下子成长了不少。 而且最兴奋的是发现许多设计上的结构在许多地方都是雷同的 包括 Objective-c ，Box2d ，之前还一直觉得 box2d 使用起来还真是繁琐 创建一个对象还得先 ref 后才能创建 简单的说设计模式就是通过规范的设计和规范的代码（当然带来的结果是繁琐的代码会多了不少）带给清晰的结构和逻辑。在代码和功能越来越多时便显的尤其重要了。 在虚拟机里面把书上的例子全跑了一遍，决心花半年时间把所有东西消化，这些demo太吸引人了。 我的终极目标是做一个架构师，不只是用户，程序员也会使用我的产品。努力奋斗，会来的。：） 需要电子书的朋友网上自行搜索把，很多资源的，官网并提供源码和例程下载。 Related Posts经不住的似水流年StarCraft2 beta coming soon?永远的扫雷英雄(开源) 登场12月串烧-年轻人就要飘逸]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2009/11/yoooo/" title="游戏开发牛书推荐"></a><p>在看一本叫 Programming Game AI By Examples 的书<br
/> （本来打算买实体书的，后来想想不能破例，还是down了本电子书 &#8220;）<br
/> 看完第二章后彻底折服了 ，写的这么好的书真是不多见的<br
/> 这才是真正的设计模式 ，寥寥几行代码就把整个世界给建模了<br
/> 结构异常清晰，细节异常周到  堪称完美的作品<br
/> 自己曾设计了不少不成型的东西，这次能见大师级别的代码确实收获颇多。<br
/> 觉得一下子成长了不少。<br
/> 而且最兴奋的是发现许多设计上的结构在许多地方都是雷同的<br
/> 包括 Objective-c ，Box2d ，之前还一直觉得 box2d 使用起来还真是繁琐<br
/> 创建一个对象还得先 ref 后才能创建</p><p>简单的说设计模式就是通过规范的设计和规范的代码（当然带来的结果是繁琐的代码会多了不少）带给清晰的结构和逻辑。在代码和功能越来越多时便显的尤其重要了。</p><p>在虚拟机里面把书上的例子全跑了一遍，决心花半年时间把所有东西消化，这些demo太吸引人了。</p><p>我的终极目标是做一个架构师，不只是用户，程序员也会使用我的产品。努力奋斗，会来的。：）</p><p>需要电子书的朋友网上自行搜索把，很多资源的，官网并提供源码和例程下载。</p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2010/03/%e7%bb%8f%e4%b8%8d%e4%bd%8f%e7%9a%84%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4/" title="经不住的似水流年">经不住的似水流年</a></li><li><a
href="http://ixhan.com/2010/02/starcraft2-beta-coming-soon/" title="StarCraft2 beta coming soon?">StarCraft2 beta coming soon?</a></li><li><a
href="http://ixhan.com/2009/12/minesweeperever/" title="永远的扫雷英雄(开源) 登场">永远的扫雷英雄(开源) 登场</a></li><li><a
href="http://ixhan.com/2009/12/dec-review/" title="12月串烧-年轻人就要飘逸">12月串烧-年轻人就要飘逸</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2009/11/yoooo/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>小试Unity游戏引擎</title><link>http://ixhan.com/2009/11/glance-at-unity/</link> <comments>http://ixhan.com/2009/11/glance-at-unity/#comments</comments> <pubDate>Sat, 07 Nov 2009 09:42:00 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[3D]]></category> <category><![CDATA[c]]></category> <category><![CDATA[game]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[png]]></category> <category><![CDATA[unity]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=159</guid> <description><![CDATA[<a
href="http://ixhan.com/2009/11/glance-at-unity/" title="小试Unity游戏引擎"></a>大四第一学期曾在学校的数字媒体实验室工作了很短时间，第一次看到现场手绘，maya做动画，zbrush绘制高模，倍感荣幸。 其中还有部分人在把弄一个游戏引擎（忘记叫什么名字了），可以让机器人在里面蹦蹦跳跳的走路。 那一刻让我想起第一次玩准3D游戏「生化危机II」的场景，震撼，鸡东的整个人在颤抖。 随着年龄的增长，对游戏的感觉也从狂热渐渐变成消磨时间，甚至忘记了小时候的梦想。 第一次游戏行业距离我这么近，却因为心有余而力不足放弃了。 回到标题上，自从 Unity 推出了免费版后，蠢蠢欲动，今天终于下载把玩了下。 一打开默认有个island的项目，场景做的很细腻，令我惊讶的是点击运行无需等待即可在场景中测试，很棒。 一遍看教程一遍开始了第一个测试项目。专业词汇挺多，没法像看程式书那样一下子就消化一堆。 最后还是不费力的做好了第一个场景，放了个对象在自己的小岛上跑了一圈，incredible! 简直想象不到眼前的居然是我做的。hohoho 暂时对Unity的感觉是，很简单，很高效，而且做出来的效果比我想象中好很多，顺便说说它使用的脚本语言 Unity JavaScript ，但是我怎么看也和我的老朋友 ActionScript3 更相似些 ，好处是可以少浪费时间看新语法书了。 附xhan&#8217;s 终极防御要塞。 这里是更多图片 Related Posts解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误now or neverTutorial of kissXML(iPhone)经不住的似水流年]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2009/11/glance-at-unity/" title="小试Unity游戏引擎"></a><p>大四第一学期曾在学校的数字媒体实验室工作了很短时间，第一次看到现场手绘，maya做动画，zbrush绘制高模，倍感荣幸。</p><p>其中还有部分人在把弄一个游戏引擎（忘记叫什么名字了），可以让机器人在里面蹦蹦跳跳的走路。</p><p>那一刻让我想起第一次玩准3D游戏「生化危机II」的场景，震撼，鸡东的整个人在颤抖。</p><p>随着年龄的增长，对游戏的感觉也从狂热渐渐变成消磨时间，甚至忘记了小时候的梦想。</p><p>第一次游戏行业距离我这么近，却因为心有余而力不足放弃了。</p><p>回到标题上，自从 Unity 推出了免费版后，蠢蠢欲动，今天终于下载把玩了下。</p><p>一打开默认有个island的项目，场景做的很细腻，令我惊讶的是点击运行无需等待即可在场景中测试，很棒。</p><p>一遍看教程一遍开始了第一个测试项目。专业词汇挺多，没法像看程式书那样一下子就消化一堆。</p><p>最后还是不费力的做好了第一个场景，放了个对象在自己的小岛上跑了一圈，incredible! 简直想象不到眼前的居然是我做的。hohoho</p><p>暂时对Unity的感觉是，很简单，很高效，而且做出来的效果比我想象中好很多，顺便说说它使用的脚本语言 Unity JavaScript ，但是我怎么看也和我的老朋友 ActionScript3 更相似些 ，好处是可以少浪费时间看新语法书了。</p><p>附xhan&#8217;s 终极防御要塞。</p><p
style="text-align: center;"><a
rel="attachment wp-att-160" href="http://ixhan.com/2009/11/glance-at-unity/bird-view/"><img
class="aligncenter size-full wp-image-160" title="bird-view" src="http://ixhan.com/wp-content/uploads/2009/11/bird-view.png" alt="bird-view" width="395" height="368" /></a></p><p>这里是更多图片</p><p><span
id="more-159"></span> <a
href='http://ixhan.com/2009/11/glance-at-unity/bird-view/' title='bird-view'><img
width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/bird-view-150x150.png" class="attachment-thumbnail" alt="bird-view" title="bird-view" /></a> <a
href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-3-16-54-pm/' title='Screen shot 2009-11-07 at 3.16.54 PM'><img
width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-3.16.54-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 3.16.54 PM" title="Screen shot 2009-11-07 at 3.16.54 PM" /></a> <a
href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-31-52-pm/' title='Screen shot 2009-11-07 at 5.31.52 PM'><img
width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.31.52-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.31.52 PM" title="Screen shot 2009-11-07 at 5.31.52 PM" /></a> <a
href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-33-03-pm/' title='Screen shot 2009-11-07 at 5.33.03 PM'><img
width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.33.03-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.33.03 PM" title="Screen shot 2009-11-07 at 5.33.03 PM" /></a> <a
href='http://ixhan.com/2009/11/glance-at-unity/screen-shot-2009-11-07-at-5-33-28-pm/' title='Screen shot 2009-11-07 at 5.33.28 PM'><img
width="150" height="150" src="http://ixhan.com/wp-content/uploads/2009/11/Screen-shot-2009-11-07-at-5.33.28-PM-150x150.png" class="attachment-thumbnail" alt="Screen shot 2009-11-07 at 5.33.28 PM" title="Screen shot 2009-11-07 at 5.33.28 PM" /></a></p><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2010/02/solve-windows-7-connect-unity-asset-server-pg_hba/" title="解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误">解决windows 7 连接 unity asset server 出现 no pg_hba.conf entry for host 的错误</a></li><li><a
href="http://ixhan.com/2010/05/now-or-never/" title="now or never">now or never</a></li><li><a
href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li><li><a
href="http://ixhan.com/2010/03/%e7%bb%8f%e4%b8%8d%e4%bd%8f%e7%9a%84%e4%bc%bc%e6%b0%b4%e6%b5%81%e5%b9%b4/" title="经不住的似水流年">经不住的似水流年</a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2009/11/glance-at-unity/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>让iPhoneApp发送带图片附件的邮件</title><link>http://ixhan.com/2009/10/iphone-app-send-email-with-image/</link> <comments>http://ixhan.com/2009/10/iphone-app-send-email-with-image/#comments</comments> <pubDate>Tue, 13 Oct 2009 03:03:37 +0000</pubDate> <dc:creator>xhan</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[c]]></category> <category><![CDATA[email]]></category> <category><![CDATA[iOS]]></category> <guid
isPermaLink="false">http://ixhan.com/?p=73</guid> <description><![CDATA[<a
href="http://ixhan.com/2009/10/iphone-app-send-email-with-image/" title="让iPhoneApp发送带图片附件的邮件"></a>更新（Nov 9,2009）: 在3.0系统中，sdk 提供了 MFMailComposeViewController 来显示发件界面，并提供附件功能。 if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mcvc = [[[MFMailComposeViewController alloc] init] autorelease]; mcvc.mailComposeDelegate = self; [mcvc setSubject:@"Here's a great photo!"]; NSString *body = @&#8221;&#60;h1&#62;Check this out&#60;/h1&#62;&#60;p&#62;I selected this image from the &#60;code&#62;&#60;b&#62;UIImagePickerController&#60;/b&#62;&#60;/code&#62;.&#60;/p&#62;&#8221;; [mcvc setMessageBody:body isHTML:YES]; &#8230;<p
class="read-more"><a
href="http://ixhan.com/2009/10/iphone-app-send-email-with-image/">Read more &#187;</a></p>]]></description> <content:encoded><![CDATA[<a
href="http://ixhan.com/2009/10/iphone-app-send-email-with-image/" title="让iPhoneApp发送带图片附件的邮件"></a><p>更新（Nov 9,2009）:</p><p>在3.0系统中，sdk 提供了 MFMailComposeViewController 来显示发件界面，并提供附件功能。</p><blockquote><p>if ([MFMailComposeViewController canSendMail])<br
/> {<br
/> MFMailComposeViewController *mcvc = [[[MFMailComposeViewController alloc] init] autorelease];<br
/> mcvc.mailComposeDelegate = self;<br
/> [mcvc setSubject:@"Here's a great photo!"];<br
/> NSString *body = @&#8221;&lt;h1&gt;Check this out&lt;/h1&gt;&lt;p&gt;I selected this image from the &lt;code&gt;&lt;b&gt;UIImagePickerController&lt;/b&gt;&lt;/code&gt;.&lt;/p&gt;&#8221;;<br
/> [mcvc setMessageBody:body isHTML:YES];<br
/> [mcvc addAttachmentData:UIImageJPEGRepresentation(image, 1.0f) mimeType:@"image/jpeg" fileName:@"pickerimage.jpg"];<br
/> [self presentModalViewController:mcvc animated:YES];<br
/> }</p></blockquote><p>在程序中如何启动系统的Email程序并在内容中添加图片附件？<br
/> 以下是代码：</p><pre class="brush: cpp; title: ; notranslate">
- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength data:(NSData *)imgData {
static const char *encodingTable = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&quot;;
const unsigned char *bytes = [imgData bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:[imgData length]];
unsigned long ixtext = 0;
unsigned long lentext = [imgData length];
long ctremaining = 0;
unsigned char inbuf[3], outbuf[4];
short i = 0;
short charsonline = 0, ctcopy = 0;
unsigned long ix = 0;
while( YES ) {
ctremaining = lentext - ixtext;
if( ctremaining &amp;lt;= 0 ) break;
for( i = 0; i &amp;lt; 3; i++ ) {
ix = ixtext + i;
if( ix &amp;lt; lentext ) inbuf[i] = bytes[ix]; 			else inbuf [i] = 0; 		} 		 		outbuf [0] = (inbuf [0] &amp;amp; 0xFC) &amp;gt;&amp;gt; 2;
outbuf [1] = ((inbuf [0] &amp;amp; 0x03) &amp;lt;&amp;lt; 4) | ((inbuf [1] &amp;amp; 0xF0) &amp;gt;&amp;gt; 4);
outbuf [2] = ((inbuf [1] &amp;amp; 0x0F) &amp;lt;&amp;lt; 2) | ((inbuf [2] &amp;amp; 0xC0) &amp;gt;&amp;gt; 6);
outbuf [3] = inbuf [2] &amp;amp; 0x3F;
ctcopy = 4;
switch( ctremaining ) {
case 1:
ctcopy = 2;
break;
case 2:
ctcopy = 3;
break;
}
for( i = 0; i &amp;lt; ctcopy; i++ )
[result appendFormat:@&quot;%c&quot;, encodingTable[outbuf[i]]];
for( i = ctcopy; i &amp;lt; 4; i++ ) 			[result appendFormat:@&quot;%c&quot;,'=']; 		 		ixtext += 3; 		charsonline += 4; 		 		if( lineLength &amp;gt; 0 ) {
if (charsonline &amp;gt;= lineLength) {
charsonline = 0;
[result appendString:@&quot;\n&quot;];
}
}
}
return result;
}
</pre><pre class="brush: cpp; title: ; notranslate">
- (void) emailButtonPressed:(id)sender {
NSString *body = @&quot;&quot;;
NSData *imageData = nil ;
NSString* dataStr = nil ;
for (PhotoItem* item in _photoBoardView.itemsSelected) {
imageData = UIImageJPEGRepresentation(item.photo.image.image,0.9);
dataStr = [self base64EncodingWithLineLength:0 data:imageData];
body = [body stringByAppendingFormat:@&quot;&lt;strong&gt;&lt;img src=&quot;data:image/jpg;base64,%@&quot; alt=&quot; image&quot; /&gt;&lt;/strong&gt;&quot;,dataStr];
}
body = [body stringByAppendingString:@&quot;&quot;];
NSString *encoded = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *atitle = [[@&quot;&quot; stringByAppendingFormat:@&quot;title: %@&quot;, @&quot;Image &quot;] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString * urlString = [@&quot;&quot; stringByAppendingFormat:@&quot;mailto:%@?subject=%@&amp;amp;body=%@&quot;, @&quot;&quot;,atitle, encoded];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
</pre><h3  class="related_post_title">Related Posts</h3><ul
class="related_post"><li><a
href="http://ixhan.com/2010/05/now-or-never/" title="now or never">now or never</a></li><li><a
href="http://ixhan.com/2010/04/a-new-approach-to-my-career/" title="A new approach to my career">A new approach to my career</a></li><li><a
href="http://ixhan.com/2010/03/tutorial-of-kissxml-iphone/" title="Tutorial of  kissXML(iPhone)">Tutorial of  kissXML(iPhone)</a></li><li><a
href="http://ixhan.com/2010/02/what-is-ipad-all-about/" title="What is iPad All About?  ">What is iPad All About? </a></li></ul>]]></content:encoded> <wfw:commentRss>http://ixhan.com/2009/10/iphone-app-send-email-with-image/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
