﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客- 攀升·Uranus-随笔分类-iOS</title><link>http://www.cppblog.com/iuranus/category/15682.html</link><description>&lt;br&gt;&lt;font color="#ADFF2F"&gt;Something Different，Something New&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Mon, 02 Feb 2015 20:15:54 GMT</lastBuildDate><pubDate>Mon, 02 Feb 2015 20:15:54 GMT</pubDate><ttl>60</ttl><item><title>OBJECTIVE C summary</title><link>http://www.cppblog.com/iuranus/archive/2015/02/02/209702.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Sun, 01 Feb 2015 18:18:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2015/02/02/209702.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/209702.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2015/02/02/209702.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/209702.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/209702.html</trackback:ping><description><![CDATA[<div>
<div>- Primitive</div>
<div>Basic C primitive type are&nbsp;available in objective C</div>
<div>char/bool/int/long int/float/double/</div>
<div>BOOL defines yes/true/1 and no/false/0</div>
<div>&nbsp;</div>
<div>- Additional&nbsp;Class</div>
<div>NSInteger, NSUInteger,&nbsp;NSFloat, NSNumber</div>
<div>for 64bit&nbsp;and 32bit CPU, the size of long, int may different, objective has additional class for these problem</div>
<div><br />
</div>
<div>-Special</div>
<div>id: id&nbsp;is a pointer&nbsp;which points to a&nbsp;object derived from NSObject.&#238;&#238;</div>
<div>nil: nil&nbsp;== NULL in c. nil means a NSObject point to a null object/ nothing</div>
<div>Nil: null class</div>
<div>SEL: is type from selector, define a method name.&nbsp;</div>
<div>NSString(@), BOOL (yes, no)</div>
<div><br />
</div>
<div>[OOP]</div>
<div>@interface: define the class, method declaration&nbsp;</div>
<div>@implementation: detail the interface</div>
<div><br />
</div>
<div>uppercast/downcast</div>
<div><br />
</div>
<div>[Memery]</div>
<div>Stack</div>
<div>Heap</div>
</div>
<div></div>
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);<img src ="http://www.cppblog.com/iuranus/aggbug/209702.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2015-02-02 02:18 <a href="http://www.cppblog.com/iuranus/archive/2015/02/02/209702.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iPad, PC, Mac Connect to a mac ox lion </title><link>http://www.cppblog.com/iuranus/archive/2011/11/10/159912.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Thu, 10 Nov 2011 06:22:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/11/10/159912.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/159912.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/11/10/159912.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/159912.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/159912.html</trackback:ping><description><![CDATA[Three accounts, test1 on iPad using Mocha VNC Lite, test2 on PC run VNC View, test3 on Mac using Screen sharing, remotely login in to a osx lion 10.7, and&nbsp;simultaneously run the different program.<br />Which indicates that osx lion supports multip-user login in, meanwhile, it allocates specific session and space for individual user.<br /><img src ="http://www.cppblog.com/iuranus/aggbug/159912.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-11-10 14:22 <a href="http://www.cppblog.com/iuranus/archive/2011/11/10/159912.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>机经</title><link>http://www.cppblog.com/iuranus/archive/2011/11/08/159841.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 08 Nov 2011 15:11:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/11/08/159841.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/159841.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/11/08/159841.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/159841.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/159841.html</trackback:ping><description><![CDATA[<a href="/Files/iuranus/test.pdf">/Files/iuranus/test.pdf</a><img src ="http://www.cppblog.com/iuranus/aggbug/159841.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-11-08 23:11 <a href="http://www.cppblog.com/iuranus/archive/2011/11/08/159841.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UIView, UITouch, UIEvent 关系</title><link>http://www.cppblog.com/iuranus/archive/2011/04/13/144109.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Wed, 13 Apr 2011 03:54:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/04/13/144109.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/144109.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/04/13/144109.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/144109.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/144109.html</trackback:ping><description><![CDATA[<div>&nbsp;<img height=563 alt="" src="http://www.cppblog.com/images/cppblog_com/iuranus/image.jpg" width=753 border=0></div>
<img src ="http://www.cppblog.com/iuranus/aggbug/144109.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-04-13 11:54 <a href="http://www.cppblog.com/iuranus/archive/2011/04/13/144109.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mac 上看网络数据</title><link>http://www.cppblog.com/iuranus/archive/2011/03/29/142954.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 29 Mar 2011 08:59:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/03/29/142954.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/142954.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/03/29/142954.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/142954.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/142954.html</trackback:ping><description><![CDATA[packet peeper<br><a href="http://sourceforge.net/projects/packetpeeper/"><u><font color=#0000ff><br><br>http://sourceforge.net/projects/packetpeeper/</font></u></a>
<img src ="http://www.cppblog.com/iuranus/aggbug/142954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-03-29 16:59 <a href="http://www.cppblog.com/iuranus/archive/2011/03/29/142954.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[webView loadHTMLString: baseURL:方法使用问题</title><link>http://www.cppblog.com/iuranus/archive/2011/03/22/142509.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 22 Mar 2011 12:02:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/03/22/142509.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/142509.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/03/22/142509.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/142509.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/142509.html</trackback:ping><description><![CDATA[<span class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><span class=Apple-style-span style="FONT-SIZE: 14px; COLOR: rgb(68,68,68); LINE-HEIGHT: 22px; FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif; BORDER-COLLAPSE: collapse; TEXT-ALIGN: left">解析某网页HTML得到了此篇文章的标题和正文内容，并用loadHTMLString:baseURL:方法在<span class=t_tag style="CURSOR: pointer; LINE-HEIGHT: normal; BORDER-BOTTOM: rgb(255,0,0) 1px solid; WHITE-SPACE: nowrap; WORD-WRAP: break-word" onclick=tagshow(event) href="tag.php?name=UIWebView">UIWebView</span>中显示出来，但没有任何样式。<br style="LINE-HEIGHT: normal; WORD-WRAP: break-word"><span class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><span class=Apple-style-span style="FONT-SIZE: 14px; COLOR: rgb(68,68,68); LINE-HEIGHT: 22px; FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif; BORDER-COLLAPSE: collapse; TEXT-ALIGN: left">把CSS也加到工程里面，然后
<div class=blockcode style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 0px; BACKGROUND-POSITION: 0px 0px; BORDER-TOP: rgb(204,204,204) 1px solid; OVERFLOW-Y: hidden; PADDING-LEFT: 10px; BACKGROUND-IMAGE: url(http://tiny4cocoa.com/images/default/codebg.gif); OVERFLOW-X: hidden; PADDING-BOTTOM: 5px; MARGIN: 10px 0px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 586px; LINE-HEIGHT: normal; PADDING-TOP: 10px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(247,247,247); WORD-WRAP: break-word; background-origin: initial; background-clip: initial">
<div id=code0 style="LINE-HEIGHT: normal; WORD-WRAP: break-word">
<ol style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 0px 10px; LINE-HEIGHT: normal; PADDING-TOP: 0px; WORD-WRAP: break-word">
    <li style="PADDING-RIGHT: 0px; PADDING-LEFT: 10px; FONT-SIZE: 12px; PADDING-BOTTOM: 0px; MARGIN: 0px 0px 0px 2em; LINE-HEIGHT: 1.8em; PADDING-TOP: 0px; FONT-FAMILY: Monaco, Consolas, ''Lucida Console'', ''Courier New'', serif; WORD-WRAP: break-word">[webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];</li>
</ol>
</div>
<em style="FONT-SIZE: 12px; MARGIN-LEFT: 43px; CURSOR: pointer; COLOR: rgb(102,102,102); LINE-HEIGHT: normal; FONT-STYLE: normal; TEXT-ALIGN: left; WORD-WRAP: break-word" onclick="copycode($('code0'));">复制代码</em></div>
这样baseURL就指向了程序的资源路径，这样Html代码就和css是一个路径的。当然baseURL也可以写一个网络路径，这样就可以用网络上的CSS了。<br style="LINE-HEIGHT: normal; WORD-WRAP: break-word"><br style="LINE-HEIGHT: normal; WORD-WRAP: break-word">Javascript也是一样的道理，但是要注意，.js文件默认会被当作代码，所以把js文件加入工程后，需要到XCode左栏的资源树，找到Targerts-&gt;(你的程序名字)-&gt;Compile Sources那里，找到新加入的js文件，把它们拖到Targerts-&gt;(你的程序名字)-&gt;Copy Bundle Resources里面去，就可以了。<br style="LINE-HEIGHT: normal; WORD-WRAP: break-word"><br style="LINE-HEIGHT: normal; WORD-WRAP: break-word">加入文件到项目的时候有两个选项，一个叫做&#8220;Recursively create groups for any added folders&#8221;一个叫做&#8220;Create Folder References for any added folders&#8221;。我们一般用前者，这样所有加进来的文件都在资源目录的根目录。如果你需要你的JS或者CSS有目录结构，不跟HTML在一起，而是有相对路径关系的话，你可以用第二个选项，加入一个目录进来，目录里面的文件进入资源的时候会保持相对路径关系。</span></span><br></span></span>
<img src ="http://www.cppblog.com/iuranus/aggbug/142509.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-03-22 20:02 <a href="http://www.cppblog.com/iuranus/archive/2011/03/22/142509.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xCode 4.0 issue list</title><link>http://www.cppblog.com/iuranus/archive/2011/03/22/142508.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 22 Mar 2011 11:57:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/03/22/142508.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/142508.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/03/22/142508.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/142508.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/142508.html</trackback:ping><description><![CDATA[<span class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">1. iOS 4.3 documentation can not found in xCode 4.0, please going into&nbsp;<span class=Apple-style-span style="FONT-SIZE: 13px; FONT-FAMILY: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif">XCode | Preferences, under the Documentation tab, get iOS4.3 Library(458M)</span></span> 
<img src ="http://www.cppblog.com/iuranus/aggbug/142508.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-03-22 19:57 <a href="http://www.cppblog.com/iuranus/archive/2011/03/22/142508.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iOS书籍随笔</title><link>http://www.cppblog.com/iuranus/archive/2011/03/10/141492.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Thu, 10 Mar 2011 04:53:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/03/10/141492.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/141492.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/03/10/141492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/141492.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/141492.html</trackback:ping><description><![CDATA[- [iPhone开发书籍大全].Programming.in.Objective-C.2.0.2nd(Addison.Wesley.2009)<br>&nbsp;&nbsp; 关于深浅拷贝讲的透彻<br>- Programming.in.Objective-C.2.0.2nd(Addison.Wesley.2009)<br>&nbsp;&nbsp; 归档，NSCopying，NSCoding<br><br>
<img src ="http://www.cppblog.com/iuranus/aggbug/141492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-03-10 12:53 <a href="http://www.cppblog.com/iuranus/archive/2011/03/10/141492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iOS写文件补充</title><link>http://www.cppblog.com/iuranus/archive/2011/03/09/141442.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Wed, 09 Mar 2011 09:51:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/03/09/141442.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/141442.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/03/09/141442.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/141442.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/141442.html</trackback:ping><description><![CDATA[<span>
<p>一 系统内置对象读写至文件<span><br><br>- If your objects are of type NSString,NSDictionary,NSArray,NSDate,NSData, or NSNumber, you can use the writeToFile:atomically: method implemented in these classes to write your data to a file. In the case of writing out a dictionary or an array, this method writes the data to the file in the format of an XML property list. Program 19.1 shows how the dictionary you created as a simple glossary in Chapter 15,&#8220;Numbers, Strings, and Collections,&#8221; can be written to a file as a property list.</span></p>
<p>&nbsp;<span>Program 19.1</span></p>
<p><span>#import &lt;Foundation/NSObject.h&gt;</span></p>
<p><span>#import &lt;Foundation/NSString.h&gt;</span></p>
<p><span>#import &lt;Foundation/NSDictionary.h&gt;</span></p>
<p><span>#import &lt;Foundation/NSAutoreleasePool.h&gt;</span></p>
<p><span>int main (int argc, char *argv[])</span></p>
<p><span>
<p><span>int main (int argc, char *argv[])</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;</span>{</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>NSAutoreleasePool<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>* pool = [[NSAutoreleasePool alloc] init];</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>NSDictionary<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>*glossary =</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>[NSDictionary<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>dictionaryWithObjectsAndKeys:</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>@&#8221;A class defined so other classes can inherit from it.&#8221;, @&#8221;abstract class&#8221;,</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>@&#8221;To implement all the methods defined in a protocol&#8221;, @&#8221;adopt&#8221;,</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>@&#8221;Storing an object for later use. &#8220;,<span>&nbsp;&nbsp;</span>@&#8221;archiving&#8221;,</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>nil</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>];</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>if ([glossary writeToFile: @&#8221;glossary&#8221;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>atomically: YES] == NO)</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>NSLog (@&#8221;Save to file failed!&#8221;);</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>[pool drain];</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>return 0;</span></p>
<p align=left><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;}</span></p>
<p align=left><span><br></span></p>
<p align=left><span>-&nbsp;</span><font face="Calibri, sans-serif"><span>To read an XML property list from a file into your program, you use the&nbsp;</span></font><span>dictionaryWithContentsOfFile: or arrayWithContentsOfFile: methods.To read&nbsp;</span><font face="Calibri, sans-serif"><span>back data, use the dataWithContentsOfFile: method; to read back string objects, use&nbsp;</span></font><span>the stringWithContentsOfFile:method. Program 19.2 reads back the glossary written&nbsp;</span><span>in Program 19.1 and then displays its contents. &nbsp;</span></p>
<p align=left>
<p align=left><font face="Calibri, sans-serif"><span><br></span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>#import &lt;Foundation/NSObject.h&gt;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>#import &lt;Foundation/NSString.h&gt;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>#import &lt;Foundation/NSDictionary.h&gt;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>#import &lt;Foundation/NSEnumerator.h&gt;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>#import &lt;Foundation/NSAutoreleasePool.h&gt;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span><br></span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>int main (int argc, char *argv[])&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>{&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp;NSAutoreleasePool &nbsp;* pool = [[NSAutoreleasePool alloc] init];&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp;NSDictionary *glossary;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span><br></span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp;glossary = [NSDictionary dictionaryWithContentsOfFile: @&#8221;glossary&#8221;];&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span><br></span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp;for ( NSString *key in glossary )&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;NSLog (@&#8221;%@: %@&#8221;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;key, [glossary objectForKey: key]);&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span><br></span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp; [pool drain];&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>&nbsp;&nbsp; &nbsp;return 0;&nbsp;</span></font></p>
<p align=left><font face="Calibri, sans-serif"><span>}&nbsp;</span></font></p>
<p>&nbsp;二 自定义对象读写至文件<span><br></span></p>
</span>
<p>&nbsp;-&nbsp;&nbsp; <span>A more flexible approach enables you to save any type of objects to a file, not just strings, </span><span>arrays, and dictionaries.This is done by creating a keyed archive using the </span><span>NSKeyedArchiver class.<br>This implies that you can&#8217;t directly archive your AddressBook using this technique because the Objective-C system doesn&#8217;t know how to archive an AddressBook object. If you tried to archive it by inserting a line such as NSKeyedArchiver archiveRootObject: myAddressBook toFile: @&#8221;addrbook.arch&#8221;]; into your program, you&#8217;d get the following message displayed if you ran the program:<br><br>*** -[AddressBook encodeWithCoder:]: selector not recognized<br>*** Uncaught exception: &lt;NSInvalidArgumentException&gt;<br>*** -[AddressBook encodeWithCoder:]: selector not recognized<br>archiveTest: received signal: Trace/BPT trap<br>To archive objects other than those listed, you must tell the system how to archive, or encode, your objects, and also how to unarchive, or decode, them.This is done by adding encodeWithCoder: and initWithCoder: methods to your class definitions, according to the &lt;NSCoding&gt; protocol. For our address book example, you&#8217;d have to add these methods to both the AddressBook and AddressCard classes.<br><br>The encodeWithCoder: method is invoked each time the archiver wants to encode an object from the specified class, and the method tells it how to do so. In a similar manner, the initWithCoder: method is invoked each time an object from the specified class is to be decoded.<br><br>Program 19.5 Addresscard.h Interface File<br>#import &lt;Foundation/NSObject.h&gt;<br>#import &lt;Foundation/NSString.h&gt;<br>#import &lt;Foundation/NSKeyedArchiver.h&gt;<br>@interface AddressCard: NSObject &lt;NSCoding, NSCopying&gt;<br>{<br>NSString&nbsp; *name;<br>NSString&nbsp; *email;<br>}<br>@property (copy, nonatomic) NSString *name, *email;<br>-(void) setName: (NSString *) theName andEmail: (NSString *) theEmail;<br>-(NSComparisonResult) compareNames: (id) element;<br>-(void) print;<br>// Additional methods for NSCopying protocol<br>-(AddressCard *) copyWithZone: (NSZone *) zone;<br>-(void) retainName: (NSString *) theName andEmail: (NSString *) theEmail;</span></p>
@end<br><br>-(void) encodeWithCoder: (NSCoder *) encoder<br>{<br>[encoder encodeObject: name forKey: @&#8221;AddressCardName&#8221;];<br>[encoder encodeObject: email forKey: @&#8221;AddressCardEmail&#8221;];<br>}<br>-(id) initWithCoder: (NSCoder *) decoder<br>{<br>name = [[decoder decodeObjectforKey: @&#8221;AddressCardName&#8221;] retain];<br>email = [[decoder decodeObjectforKey: @&#8221;AddressCardEmail&#8221;] retain];<br>return self;<br>}<br><br>#import &#8220;AddressBook.h&#8221;<br>#import &lt;Foundation/NSAu orelea ePool.h&gt;<br>int main (int argc, char *argv[])<br>{<br>&nbsp;NSString&nbsp; *aName = @&#8221;Julia Kochan&#8221;;<br>NSString&nbsp; *aEmail = @&#8221;jewls337@axlc.com&#8221;;<br>NSString&nbsp; *bName = @&#8221;Tony Iannino&#8221;;<br>NSString&nbsp; *bEmail = @&#8221;tony.iannino@techfitness.com&#8221;;<br>NSString&nbsp; *cName = @&#8221;Stephen Kochan&#8221;;<br>NSString&nbsp; *cEmail = @&#8221;steve@steve_kochan.com&#8221;;<br>NSString&nbsp; *dName = @&#8221;Jamie Baker&#8221;;<br>NSString&nbsp; *dEmail = @&#8221;jbaker@hitmail.com&#8221;;<br>NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br>AddressCard *card1 = [[AddressCard alloc] init];<br>AddressCard *card2 = [[AddressCard alloc] init];<br>AddressCard *card3 = [[AddressCard alloc] init];<br>AddressCard *card4 = [[AddressCard alloc] init];<br>AddressBook&nbsp; *myBook = [AddressBook alloc];<br>// First set up four address cards<br>[card1 setName: aName andEmail: aEmail];<br>[card2 setName: bName andEmail: bEmail];<br>[card3 setName: cName andEmail: cEmail];<br>[card4 setName: dName andEmail: dEmail];<br>myBook = [myBook initWithName: @&#8221;Steve&#8217;s Address Book&#8221;];<br>// Add some cards to the address book<br>[myBook addCard: card1];<br>[myBook addCard: card2];<br>[myBook addCard: card3];<br>[myBook addCard: card4];<br>[myBook sort];<br>if ([NSKeyedArchiver archiveRootObject: myBook toFile: @&#8221;addrbook.arch&#8221;] == NO)<br>NSLog (@&#8221;archiving failed&#8221;);<br>[card1 release];<br>[card2 release];<br>[card3 release];<br>[card4 release];<br>[myBook release];<br>[pool drain];<br>return 0;<br>}</span> <br><br>Program 19.7 shows how you can read the archive into memory to set up the address<br>book from a file.<br>Program 19.7<br>#import &#8220;AddressBook.h&#8221;<br>#import &lt;Foundation/NSAutoreleasePool.h&gt;<br>int main (int argc, char *argv[])<br>{<br>AddressBook&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myBook;<br>NSAutoreleasePool&nbsp;&nbsp; * pool = [[NSAutoreleasePool alloc] init];<br>myBook = [NSKeyedUnarchiver unarchiveObjectWithFile: @&#8221;addrbook.arch&#8221;];<br>[myBook list];<br>[pool drain];<br>return 0;<br>} <br><br>三 使用NSData读写文件<br><br>- You might not want to write your object directly to a file using the archiveRootObject:ToFile: method, as was done in the previous program examples.For example, perhaps you want to collect some or all of your objects and store them in a single archive file.You can do this in Objective-C using the general data stream object class called NSData. <br><br>int main (int argc, char *argv[])<br>{<br>NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br>Foo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myFoo1 = [[Foo alloc] init];<br>Foo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myFoo2;<br>NSMutableData&nbsp;&nbsp;&nbsp;&nbsp; *dataArea;<br>NSKeyedArchiver&nbsp;&nbsp; *archiver;<br>AddressBook&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myBook;<br>// Insert code from Program 19.7 to create an Address Book<br>// in myBook containing four address cards<br>[myFoo1 setStrVal: @&#8221;This is the string&#8221;];<br>[myFoo1 setIntVal: 12345];<br>[myFoo1 setFloatVal: 98.6];<br>// Set up a data area and connect it to an NSKeyedArchiver object<br>dataArea = [NSMutableData data];<br>archiver = [[NSKeyedArchiver alloc]<br>initForWritingWithMutableData: dataArea];<br>// Now we can begin to archive objects<br>[archiver encodeObject: myBook forKey: @&#8221;myaddrbook&#8221;];<br>[archiver encodeObject: myFoo1 forKey: @&#8221;myfoo1&#8221;];<br>[archiver finishEncoding];<br>// Write the archived data are to a file<br>if ( [dataArea writeToFile: @&#8221;myArchive&#8221; atomically: YES] == NO)<br>NSLog (@&#8221;Archiving failed!&#8221;);<br>[archiver release];<br>[myFoo1 release];<br>[pool drain];<br>return 0;<br>}<br><br>- Restoring the data from your archive file is simple:You just do things in reverse. First, you need to allocate a data area like before.Next, you need to read your archive file into the data area; then you have to create an SKeyedUnarchiver object and tell it to decode data from the specified area.You must invoke decode methods to extract and decode your archived objects.When you&#8217;re finished, you send a finishDecoding message to the NSKeyedUnarchiver object.<br><br>#import &lt;Foundation/NSObject.h&gt;<br>#import &lt;Foundation/NSAutoreleasePool.h&gt;<br>#import &lt;Foundation/NSString.h&gt;<br>#import &lt;Foundation/NSKeyedArchiver.h&gt;<br>#import &lt;Foundation/NSCoder.h&gt;<br>#import &lt;Foundation/NSData.h&gt;<br>#import &#8220;AddressBook.h&#8221;<br>#import &#8220;Foo.h&#8221;<br>int main (int argc, char *argv[])<br>{<br>NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br>NSData&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *dataArea;<br>NSKeyedUnarchiver *unarchiver;<br>Foo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myFoo1;<br>AddressBook&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myBook;<br>// Read in the archive and connect an<br>// NSKeyedUnarchiver object to it<br>dataArea = [NSData dataWithContentsOfFile: @&#8221;myArchive&#8221;];<br>if (! dataArea) {<br>NSLog (@&#8220;Can&#8217;t read back archive file!&#8221;);<br>Return (1);<br>}<br>unarchiver = [[NSKeyedUnarchiver alloc]<br>initForReadingWithData: dataArea];<br>// Decode the objects we previously stored in the archive<br>myBook = [unarchiver decodeObjectForKey: @&#8221;myaddrbook&#8221;];<br>myFoo1 = [unarchiver decodeObjectForKey: @&#8221;myfoo1&#8221;];<br>[unarchiver finishDecoding];<br>[unarchiver release];<br>// Verify that the restore was successful<br>[myBook list];<br>NSLog (<a>&#8220;%@\n%i\n%g</a>&#8221;, [myFoo1 strVal],<br>[myFoo1 intVal], [myFoo1 floatVal]);<br>[pool release];<br>return 0;<br>}<br><br>参考：Programming.in.Objective-C.2.0.2nd(Addison.Wesley.2009)<br>完
<img src ="http://www.cppblog.com/iuranus/aggbug/141442.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-03-09 17:51 <a href="http://www.cppblog.com/iuranus/archive/2011/03/09/141442.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iOS 4后台多任务</title><link>http://www.cppblog.com/iuranus/archive/2011/01/06/138063.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Thu, 06 Jan 2011 03:58:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2011/01/06/138063.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/138063.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2011/01/06/138063.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/138063.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/138063.html</trackback:ping><description><![CDATA[
<p class="MsoNormal"><span style="font-family:宋体">今天调查了下</span><span lang="EN-US">IOS
4.0 </span><span style="font-family:宋体">支持的多任务的事宜，系统是</span><span lang="EN-US">4.2</span><span style="font-family:宋体">，</span> <span style="font-family:宋体">初步结果如下：</span></p>

<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span lang="EN-US">Ios 4.0 </span><span style="font-family:
宋体">多任务不是传统意义上的多任务。只是把程序的状态保存起来，程序挂起。因为</span><span lang="EN-US">Apple</span><span style="font-family:宋体">还没准备好多任务同时运行，</span></p>

<p class="MsoNormal"><span style="font-family:宋体">主要是因为</span><span lang="EN-US">battery</span><span style="font-family:宋体">和</span><span lang="EN-US">memory</span><span style="font-family:宋体">这两个问题还没有解决。</span></p>

<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-family:宋体">现在</span><span lang="EN-US">IOS 4</span><span style="font-family:宋体">多任务支持的类型（官网）：</span><span lang="EN-US">&nbsp;&nbsp; </span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Background
audio</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
color:#333333"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Voice
over IP</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
color:#333333"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Background
location</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
color:#333333">&nbsp;<o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Push
notifications</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:
&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Local
notifications</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:
&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"><o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Task
finishing</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
color:#333333">&nbsp;- If your app is in mid-task when your customer leaves it,
the app can now keep running to finish the task.<o:p></o:p></span></p>

<p class="MsoNormal" align="left" style="margin-left:24.0pt;text-align:left;
text-indent:-18.0pt;line-height:13.5pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt"><!--[if !supportLists]--><span lang="EN-US" style="font-size:10.0pt;mso-bidi-font-size:9.0pt;font-family:Wingdings;
mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings;color:#333333"><span style="mso-list:Ignore">&#167;<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">Fast
app switching</span></strong><span lang="EN-US" style="font-size:9.0pt;font-family:
&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">&nbsp;- All developers should take
advantage of fast app switching, which allows users to leave your app and come
right back to where they were when they left - no more having to reload the
app.<o:p></o:p></span></p>

<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span lang="EN-US"><font face="宋体">我使用的是</font></span><span lang="EN-US" style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(51, 51, 51); font-weight: bold; ">Task
finishing</span><strong><span style="font-size:9.0pt;font-family:宋体;color:#333333">，</span></strong><strong><span style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"> </span></strong><strong><span style="font-size:9.0pt;font-family:宋体;color:#333333">既当用户挂起程序时，如果还有</span></strong><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">task</span></strong><strong><span style="font-size:9.0pt;font-family:宋体;color:#333333">没完成，可以把改</span></strong><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">task</span></strong><strong><span style="font-size:9.0pt;font-family:宋体;color:#333333">完成。</span></strong><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"><o:p></o:p></span></strong></p>

<p class="MsoNormal"><strong><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;
color:#333333"><o:p>&nbsp;</o:p></span></strong></p>

<p class="MsoNormal"><span style="font-size:9.0pt;font-family:宋体;color:#333333">但这个是有限制的，时间的限制，就是说你的后台程序不能执行超过某个时间。</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"><o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:9.0pt;font-family:宋体;color:#333333">我刚才打</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">log</span><span style="font-size:9.0pt;font-family:宋体;color:#333333">看了，系统返回</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">500s</span><span style="font-size:9.0pt;font-family:宋体;color:#333333">，既是</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">8</span><span style="font-size:9.0pt;font-family:宋体;color:#333333">分钟，</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333">8</span><span style="font-size:9.0pt;font-family:宋体;color:#333333">分钟如果还没执行完，就会自动把我们程序结束。</span><span lang="EN-US" style="font-size:9.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;;color:#333333"><o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:9.0pt;font-family:宋体;color:#333333"><br></span></p><p class="MsoNormal"><font  color="#333333" face="宋体"><span  style="font-size: 12px;">代码如下</span></font></p>

<p class="MsoNormal"><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 12px; "><strong>#pragma mark -</strong></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>#pragma mark Background Task Handle</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>- (void)applicationDidEnterBackground:(UIApplication *)application {</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><br></strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>// Request permission to run in the background. Provide an&nbsp;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>// expiration handler in case the task runs long.</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>NSAssert(self-&gt;bgTask == UIBackgroundTaskInvalid, nil);</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>	</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>self-&gt;bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>// Synchronize the cleanup call on the main thread in case</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>// the task catully finished at around the same time.</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>dispatch_async(dispatch_get_main_queue(), ^{</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>			</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">			</span>if (UIBackgroundTaskInvalid != self-&gt;bgTask) {</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>				</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">				</span>[application endBackgroundTask:self-&gt;bgTask];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">				</span>self-&gt;bgTask = UIBackgroundTaskInvalid;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">			</span>}</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>});</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>}];</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>	</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>// Start the long-running task and return immediately.</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),&nbsp;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">				</span> &nbsp; ^{</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span> &nbsp; // Do the work assoicated with the task.<span class="Apple-tab-span" style="white-space:pre">	</span></strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span>&nbsp;&nbsp;for(int i = 0; i &nbsp;&lt; 1000; i++) {</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//request network.</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NSLog(@"hahah %d, Time Remain = %f", i, [application backgroundTimeRemaining]);</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span> &nbsp; // Synchronize the cleanup all on the main thread in case</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span> &nbsp; // the task catully finished at around the same time.&nbsp;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span> &nbsp; dispatch_async(dispatch_get_main_queue(), ^{</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">						</span> &nbsp;&nbsp;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">						</span> &nbsp; if (UIBackgroundTaskInvalid != self-&gt;bgTask) {</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><br></strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">							</span> &nbsp; [application endBackgroundTask:self-&gt;bgTask];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">							</span> &nbsp; self-&gt;bgTask = UIBackgroundTaskInvalid;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">						</span> &nbsp; }</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">					</span> &nbsp; });</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">				</span> &nbsp; });</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>}</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>#pragma mark -</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>#pragma mark Local Notifications</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>- (void)scheduleAlarmForDate:(NSDate *)theDate {</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>	</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>UIApplication *app = [UIApplication sharedApplication];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>NSArray *oldNotifications = [app scheduledLocalNotifications];</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>	</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>// Clear out the old notification before scheduling a new one.</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>if (0 &lt; [oldNotifications count]) {</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>		</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>[app cancelAllLocalNotifications];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>}</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>	</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>// Create a new notification</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>UILocalNotification *alarm = [[UILocalNotification alloc] init];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>if (alarm) {</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><br></strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>alarm.fireDate = theDate;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>alarm.timeZone = [NSTimeZone defaultTimeZone];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>alarm.repeatInterval = 0;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>alarm.soundName = @"ping.caf";//@"default";</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>alarm.alertBody = [NSString stringWithFormat:@"Time to wake up!Now is\n[%@]",&nbsp;</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">						</span> &nbsp; [NSDate dateWithTimeIntervalSinceNow:10]];</strong></span></font></p><p class="MsoNormal"><span class="Apple-tab-span" style="white-space: pre; font-size: 12px;"><font color="#333333" face="Arial, sans-serif"><strong>		</strong></font></span></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>[app scheduleLocalNotification:alarm];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">		</span>[alarm release];</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong><span class="Apple-tab-span" style="white-space:pre">	</span>}</strong></span></font></p><p class="MsoNormal"><font color="#333333" face="Arial, sans-serif"><span style="font-size: 12px;"><strong>}&nbsp;</strong></span></font></p><p class="MsoNormal"><font  color="#333333" face="Arial, sans-serif"><span  style="font-size: 12px;"><strong>有问题留言，或者微博:</strong></span></font><a href="http://t.sina.com.cn/passionuranus">http://t.sina.com.cn/passionuranus</a></p>
<img src ="http://www.cppblog.com/iuranus/aggbug/138063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2011-01-06 11:58 <a href="http://www.cppblog.com/iuranus/archive/2011/01/06/138063.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>objective c实现配置文件+反射 工厂创建</title><link>http://www.cppblog.com/iuranus/archive/2010/12/16/136606.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Thu, 16 Dec 2010 03:00:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2010/12/16/136606.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/136606.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2010/12/16/136606.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/136606.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/136606.html</trackback:ping><description><![CDATA[
<p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; ">1. 先写plist配置文件</span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; "><br></span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">plist写到resouce里面去</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">通过NSBundle把数据取plist读出来</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; "><br></span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; "><br></span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; ">2. 通过</span><span style="font-size: 16px; ">NSClassFromString创建类</span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; ">NSClassFromString</span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; ">NSSelectorFromString</span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">正常来说，</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><strong style="line-height: normal; ">id myObj = [[NSClassFromString(@"MySpecialClass") alloc] init];</strong></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><strong style="line-height: normal; ">和</strong></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><strong style="line-height: normal; ">id myObj = [[MySpecialClass alloc] init];</strong></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">是一样的。但是，如果你的程序中并不存在MySpecialClass这个类，下面的写法会出错，而上面的写法只是返回一个空对象而已。</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">因此，在某些情况下，可以使用NSClassFromString来进行你不确定的类的初始化。</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">比如在iPhone中，NSTask可能就会出现这种情况，所以在你需要使用NSTask时，最好使用：</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">[[NSClassFromString(@"NSTask") .....]]</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">而不要直接使用[NSTask ...]这种写法。</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font size="4" face="隶书" style="line-height: normal; "><strong style="line-height: normal; "><font color="#9900ff" style="line-height: normal; ">NSClassFromString的好处是：</font></strong></font></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font size="4" face="隶书" style="line-height: normal; "><strong style="line-height: normal; "><font color="#9900ff" style="line-height: normal; ">1 弱化连接，<font color="#000000" style="line-height: normal; ">因此并不会把没有的Framework也link到程序中。</font></font></strong></font></p><span style="color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; line-height: 20px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><font size="4" face="隶书" style="line-height: normal; "><strong style="line-height: normal; "><font color="#9900ff" style="line-height: normal; ">2 不需要使用import，<font color="#000000" style="line-height: normal; ">因为类是动态加载的，只要存在就可以加载。</font></font></strong></font></span><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span style="line-height: normal; font-size: 16px; "><br style="line-height: normal; "></span></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">for (int c=0; c&lt;[classNames count]; c++) {</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span class="wp_keywordlink_affiliate" style="line-height: normal; "><a target="_blank" title="查看 NSString 的全部文章" href="http://b.imi.im/?tag=nsstring" style="cursor: url(http://www.zidou.com/myfile/zidou/ani/104.cur); line-height: 20px; color: rgb(190, 13, 93); text-decoration: none; font-size: 12px; font-family: Georgia; ">NSString</a></span>&nbsp;*className=[classNames objectAtIndex:c];</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">id class=[[<span style="line-height: normal; font-size: 16px; ">NSClassFromString</span>(className) alloc] init];</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">for (int i=0; i&lt;[params count]; i++) {</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">[class performSelector:<span style="line-height: normal; font-size: 16px; ">NSSelectorFromString</span>([<span class="wp_keywordlink_affiliate" style="line-height: normal; "><a target="_blank" title="查看 NSString 的全部文章" href="http://b.imi.im/?tag=nsstring" style="cursor: url(http://www.zidou.com/myfile/zidou/ani/104.cur); line-height: 20px; color: rgb(190, 13, 93); text-decoration: none; font-size: 12px; font-family: Georgia; ">NSString</a></span>&nbsp;stringWithFormat:@"setA%i",i])];</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">}</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">}</p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br></p><p style="line-height: normal; color: rgb(85, 85, 85); font-family: Georgia; font-size: 12px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span  style="color: rgb(0, 0, 0); font-family: Arial; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; font-size: 14px; line-height: 21px; ">有问题，请留言<br><br>新浪微博：Passionuranus</span></p>
<img src ="http://www.cppblog.com/iuranus/aggbug/136606.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2010-12-16 11:00 <a href="http://www.cppblog.com/iuranus/archive/2010/12/16/136606.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Objective C基本数据类型</title><link>http://www.cppblog.com/iuranus/archive/2010/12/14/136404.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 14 Dec 2010 10:48:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2010/12/14/136404.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/136404.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2010/12/14/136404.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/136404.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/136404.html</trackback:ping><description><![CDATA[<span class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">共三种:<br><br>1. int<br>输出格式符：%i, %d, %o %x, <br><br>2. float<br>输出格式符：%f, %e, %g<br><br>3. double<br>输出格式符：%f, %e, %g<br><br><br>4. char<br>输出格式符：%c<br><br><br>限定符：<br><br>1. long<br>long int: %li<br>long double: %Lf<br>形成long int通过在数字后面加L.<br>long int number = 123324123234123L;<br><br>2. long long<br>long long int: %lli<br><br>3. short<br>short int: %hi<br><br>4. unsigned<br><br><br><br>short<br><br>unsigned<br><br>signed<br></span>
<img src ="http://www.cppblog.com/iuranus/aggbug/136404.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2010-12-14 18:48 <a href="http://www.cppblog.com/iuranus/archive/2010/12/14/136404.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iPhone发布前准备</title><link>http://www.cppblog.com/iuranus/archive/2010/12/14/136403.html</link><dc:creator>攀升</dc:creator><author>攀升</author><pubDate>Tue, 14 Dec 2010 10:33:00 GMT</pubDate><guid>http://www.cppblog.com/iuranus/archive/2010/12/14/136403.html</guid><wfw:comment>http://www.cppblog.com/iuranus/comments/136403.html</wfw:comment><comments>http://www.cppblog.com/iuranus/archive/2010/12/14/136403.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuranus/comments/commentRss/136403.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuranus/services/trackbacks/136403.html</trackback:ping><description><![CDATA[没时间写blog，但我发两个官方文档大家可以作为参考: &nbsp;&nbsp;
<div>1. 如何编译distribution， adhoc等版本</div>
<div><a href="http://wenku.baidu.com/view/ba98defff705cc175527094c.html">http://wenku.baidu.com/view/ba98defff705cc175527094c.html</a></div>
<div>2. 上传前的准备,既是使用itunes connect&nbsp;</div>
<div><a href="http://wenku.baidu.com/view/949a954de518964bcf847c7c.html">http://wenku.baidu.com/view/949a954de518964bcf847c7c.html</a></div>
<br>有问题，请留言<br><br>新浪微博：Passionuranus
<img src ="http://www.cppblog.com/iuranus/aggbug/136403.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuranus/" target="_blank">攀升</a> 2010-12-14 18:33 <a href="http://www.cppblog.com/iuranus/archive/2010/12/14/136403.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>