<?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; iPhone/Mac/ObjectC</title>
	<atom:link href="http://www.ieliwb.com/category/iphone-sdk-dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ieliwb.com</link>
	<description>灵感的来临，没有任何预兆；灵感的消失，也不会有告别仪式；用文字记下她们吧，让灵感永存……</description>
	<lastBuildDate>Wed, 04 Aug 2010 02:52:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[转]Converting iPhone Apps to Universal Apps</title>
		<link>http://www.ieliwb.com/converting-iphone-apps-to-universal-apps/</link>
		<comments>http://www.ieliwb.com/converting-iphone-apps-to-universal-apps/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:53:54 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[Universal]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/?p=255</guid>
		<description><![CDATA[<blockquote><p>很棒的一篇关于Universal程序的心得,原文地址:http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html<br />
(需翻墙)</p></blockquote>
<p>Well, the NDA has finally lift[......]</p><p class='read-more'><a href='http://www.ieliwb.com/converting-iphone-apps-to-universal-apps/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<blockquote><p>很棒的一篇关于Universal程序的心得,原文地址:http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html<br />
(需翻墙)</p></blockquote>
<p>Well, the NDA has finally lifted, so we can start talking about iPhone SDK 3.2 and the iPad. The logical starting place seemed to be how to convert your existing applications into a &#8220;Universal App&#8221; that runs natively both on the iPad and the iPhone/iPod touch. Now, a lot of you have likely already had to figure this stuff out so you could get your updated app on the store today, but for those who didn&#8217;t go the early adopter route, let&#8217;s take a few minutes to look at the process. It&#8217;s pretty straightforward but there are a few gotchas.<br />
<blockquote><i><b>Note</b>: There are some additional things you should know, so read <a href="http://www.ieliwb.com/ipad-iphone-universal-dev/" target="_blank">this post also</a> before tackling your update.</i></p></blockquote>
<p><H3>Targeting All Devices</h3>
<p>The first thing you have to do is identify that you want to build your existing application as a universal application. For this article, I&#8217;m using the Xcode project from <a href="http://code.google.com/p/iphoneparticles/">OpenGL ES Particle Generator Application</a>, but I&#8217;ll try to keep the information general. <i>Note: the following step is not needed if you use Xcode&#8217;s <b>Update Project Target for iPad</b> option talked about <a href="http://www.ieliwb.com/ipad-iphone-universal-dev/" target="_blank">here</a></i>.</p>
<p>Bring up your Project Info window in Xcode by either double-clicking on your project&#8217;s root node in the <em>Groups &#038; Files</em> pane or selecting <strong>Edit Project Settings</strong> from the <strong>Project</strong> menu and then navigate to the <em>Build</em> tab. Now, the change we&#8217;re about to make needs to be made to all configurations, so make sure that the <em>Configuration</em> popup menu is set to <em>All Configurations</em>, otherwise you&#8217;ll only make the change on one configuration.</p>
<p>We need to change a setting called <em>Target Device Family</em>, so type <em>Target</em> into the search bar, or just search for that entry manually (it&#8217;ll be under the <em>Deployment</em> heading). Right now, it should look like this:</p>
<div style="text-align:center;"><img src="http://www.ieliwb.com/u/img/Universal-1.png" border="0" width="809" height="673" /></div>
<p>See how it says <em>iPhone</em>? Yeah, you know what to do. Click on it and change it so it reads <em>iPhone/iPad</em>, like so:</p>
<div style="text-align:center;"><img src="http://www.ieliwb.com/u/img/select_target.png" border="0" width="809" height="673" /></div>
<p>Good! now you&#8217;re done, right? Most likely, no.</p>
<p><H3>Auditing for Hardcoded Sizes</H3><br />The next thing you&#8217;re going to want to do is audit your application to see if you hard-coded the screen size anywhere in your application. You shouldn&#8217;t have hardcoded those values, but let&#8217;s face it, we&#8217;ve all done it. A <em>Project Find</em> (&#8984;&#x21e7;F) for <em>320</em> and <em>480</em> and that should turn up any of those hardcoded values. In the Particle Generator code, I did it in only one place, in code that creates a <font face="monospace">UIImage</font> of the OpenGL view. The line of code where I did it looks like this:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    CGImageRef imageRef = CGImageCreate(<span class="constant constant_numeric constant_numeric_c">320</span>, <span class="constant constant_numeric constant_numeric_c">480</span>, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, <span class="constant constant_language constant_language_c">NULL</span>, <span class="constant constant_language constant_language_objc">NO</span>, renderingIntent);</span></pre>
<p>Usually, the fix for this will be obvious. Instead of hardcoding, you want to pull the width and height from the OpenGL view. The code where I did it actually exists on the <font face="monospace">GLView</font> class, so I can fix it like so:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    CGImageRef imageRef = CGImageCreate(self.frame.size.width, self.frame.size.height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, <span class="constant constant_language constant_language_c">NULL</span>, <span class="constant constant_language constant_language_objc">NO</span>, renderingIntent);</span></pre>
<p>But, what if what you&#8217;ve hardcoded is the actual size of the view? Then you need to pull the size from the main screen instead of the view. That&#8217;s easy enough to do.
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    UIScreen *screen = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>UIScreen <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">mainScreen</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>myView <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFrame<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>screen <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">applicationFrame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;</span></pre>
<p><H3>Dealing with Different Window Sizes</H3><br />Most likely your application&#8217;s one instance of <font face="monospace">UIWindow</font> is contained in your <em>MainWindow.xib</em> file that gets loaded automatically. Most likely, that Window is hardcoded to 320&#215;480. Now, you might think that you can just go into Interface Builder and set the autosize attributes for the window and it will get resized for you at launch. You would be wrong. There is no automatic check to make sure your window is the right size.</p>
<p>You have to make sure that the window is the right size for the device you&#8217;re running on. There are, basically, two ways of doing that. If your application is such that you just need to resize the window and your autosize attributes will take care of making everything look nice, then you can just handle this programmatically in <em>applicationDidFinishLaunching:</em> by setting the window&#8217;s size to the size of the screen, less the status bar andy any other objects controlled by the iPhone OS (this is known as the <em>Application Frame</em>). Doing this looks almost exactly like setting the size of the view above:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    <span class="support support_type support_type_quartz">CGRect</span>  rect = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>UIScreen <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">mainScreen</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">bounds</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFrame<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>rect</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;</span></pre>
<p>Now, this is actually a good approach for the <em>Particles</em> application because it has one full-screen view. However, the iPad and the iPhone are really different devices, and there are several UI components available on the iPad that aren&#8217;t available (at least yet) on the iPhone, such as split views and pop up views. For many applications, especially complex applications using a lot of <font face="monospace">UIKit</font> views and controls, you&#8217;re probably going to want to provide completely different NIB file based on which device on which the code is running.</p>
<p><H3>Info.Plist Device-Specific Entries</H3><br />The one really important nib file in every iPhone application is, of course, <em>MainWindow.xib</em>, and there has to be a way to tell your application to use a different <em>MainWindow.xib</em> for different devices. In fact, there is. For each key that <em>Info.plist</em> supports, such <font face="monospace">NSMainNibFile</font>, which is used to specify the name of the application&#8217;s main nib file, you can now specify device-specific entries. If you provide a device-specific entry for the device the application is currently running on, it will use the device-specific value, otherwise it will just use the normal value.</p>
<p>Device-specific keys are exactly the same as the original or default key except the key name is followed by a tilde (~) and then the name of the device in all-lowercase letters. So, to tell our application to load a different nib file for the iPad, we can add a key called <font face="monospace">NSMainNibFile~ipad</font> and then specify the name of the nib file to use when launching on an iPad. For the iPhone and iPod touch, it will continue to use the default value, <em>MainWindow.xib</em>, but for the iPad, it will use the nib file you&#8217;ve specified in the new, device-specific key.</p>
<p>You can add a new version of <em>MainWindow.xib</em> to your project by selecting the <em>Resources</em> group and choosing <strong>Add New File</strong> from the <strong>File</strong> menu. From the New File Assistant, select <em>User Interface</em> from under the iPhone OS, then select <em>Application XIB</em>, and make sure you select the right device in the <em>Product</em> drop-down.</p>
<div style="text-align:center;"><img src="http://www.ieliwb.com/u/img/Universal-2.png" border="0" width="763" height="581" /></div>
<p>Make sure you remember to connect all the outlets and actions in this new nib to the same outlets and actions you used in the other nib. Remember, only one of the application nibs will be loaded, so there&#8217;s no conflict.</p>
<p>For any key in the <em>Info.plist</em> file, you can use this same technique to override the default value with a device specific. You could, for example, have the iPhone version start in Portrait and the iPad version start in landscape, like so:
<pre class="textmate-source mac_classic"><span class="text text_xml">    ...    <span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">key</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>UIInterfaceOrientation<span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;/</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">key</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>    <span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">string</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>UIInterfaceOrientationPortrait<span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;/</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">string</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>    <span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">key</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>UIInterfaceOrientation~ipad<span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;/</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">key</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>    <span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">string</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>UIInterfaceOrientationLandscapeLeft<span class="meta meta_tag meta_tag_xml"><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&lt;/</span><span class="entity entity_name entity_name_tag entity_name_tag_localname entity_name_tag_localname_xml">string</span><span class="punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_xml">&gt;</span></span>    ...</span></pre>
<p><H3>Programmatically Determining Device</H3><br />If you have code that needs to vary depending on whether it&#8217;s running on the iPad or iPhone/iPod touch, Apple has provided a new macro called <font face="monospace">UI_USER_INTERFACE_IDIOM()</font> that will tell you that. There are currently two values defined, <font face="monospace">UIUserInterfaceIdiomPhone</font> and <font face="monospace">UIUserInterfaceIdiomPad</font>, and this macro will return the value that corresponds to the device being run. So, for example, if you needed to push a view controller onto the navigation stack, but wanted a different nib used for the iPad than the iPhone, you might do this:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    MyController *controller = <span class="constant constant_language constant_language_objc">nil</span>;

    <span class="keyword keyword_control keyword_control_c">if</span> (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)        controller = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>MyController <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">initWithNibName<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>MyiPadNib<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span> <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">bundle<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;    <span class="keyword keyword_control keyword_control_c">else</span>        controller = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>MyController <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">initWithNibName<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>MyiPodNib<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span> <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">bundle<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span>.navigationController <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">pushViewController<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>controller <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">animated<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">YES</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>controller <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">release</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;</span></pre>
<p>If you need finer-grain control, and need to know exactly which device, there&#8217;s no official, supported way to determine the exact device. The vast majority of the time you you think you need to know the device, you don&#8217;t actually need to know the device, you just need to know which features are supported. Even though you can find code around the web that will determine the device based on <font face="monospace">UIDevice</font>, you really shouldn&#8217;t base your logic on that because such code can be fragile since you don&#8217;t know what future devices will exist, or what features they will have.</p>
<p>In cases like the Image Picker, Apple provides a way to determine which features are available on your device, such as whether there&#8217;s a camera, and whether that camera supports video. When Apple hasn&#8217;t provide a specific check or test, what you can do is use <font face="monospace">NSClassFromString()</font>, which (as is probably obvious from the name) creates a <font face="monospace">Class</font> instance based on the name of a class contained in a string. If this returns <font face="monospace">nil</font>, then you know the class you&#8217;re asking about isn&#8217;t available. You can wrap your code that uses classes that aren&#8217;t available everywhere in these checks and make code that works correctly on all devices, and will continue to do so in the future (for the most part &#8211; it&#8217;s never possible to 100% future-proof code). Here&#8217;s an example of checking for the existence of the <font face="monospace">UISplitViewController</font>, which is a new class only available on the iPad:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    <span class="storage storage_type storage_type_objc">Class</span> splitViewController =<span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_cocoa"> </span><span class="support support_function support_function_cocoa">NSClassFromString</span>(<span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>UISplitViewController<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>);    <span class="keyword keyword_control keyword_control_c">if</span> (splitViewController)    <span class="meta meta_block meta_block_c">{       UISplitViewController* mySplitViewController = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>splitVCClass <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">init</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;       <span class="comment comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_c">//</span> ... configure, use, then release</span>    }</span></span></pre>
<p>You can do something similar with C functions by checking if the function is <font face="monospace">NULL</font> For example, one of the frameworks added with iPhone SDK 3.2 is <em>CoreText.framework</em>. If we wanted to use the function <font face="monospace">CTFontCreateWithName()</font> to create a new font using that framework, we could wrap the logic in an interface idiom check, like above, or we could just check to see if the function we want to use exists by seeing if the symbol <font face="monospace">CTFontCreateWithName</font> is <font face="monospace">NULL</font> at runtime, like so:
<pre class="textmate-source mac_classic"><span class="source source_objc source_objc_iphone">    <span class="keyword keyword_control keyword_control_c">if</span> (CTFontCreateWithName != <span class="constant constant_language constant_language_c">NULL</span>)        CTFontFontRef myFont = CTFontCreateWithName(<span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>Comic Sans<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>, <span class="constant constant_numeric constant_numeric_c">14.0</span>, <span class="constant constant_language constant_language_c">NULL</span>);</span></pre>
<p><H3>Go, Go, Gadget iPad, Go!</H3><br />Well, that pretty much covers the basics you&#8217;ll need to convert your existing iPhone apps to Universal Apps. The more complex your app, the more likely you&#8217;ll want to consider doing separate iPad and iPhone applications. I&#8217;ll show how to add another target to your Xcode project so you can generate two applications from the same project in a future post. For many apps, however, this should be enough to get you porting away, so port away!<BR></BR><BR></BR> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/converting-iphone-apps-to-universal-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Socket communication on the iPhone/iPad</title>
		<link>http://www.ieliwb.com/socket-communication-on-the-iphone-ipad/</link>
		<comments>http://www.ieliwb.com/socket-communication-on-the-iphone-ipad/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 06:06:25 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/socket-communication-on-the-iphoneipad/</guid>
		<description><![CDATA[<p>Some information on socket implementation on the iPhone, because I&#8217;ve found no information on the web and think this could be useful for others [......]</p><p class='read-more'><a href='http://www.ieliwb.com/socket-communication-on-the-iphone-ipad/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>Some information on socket implementation on the iPhone, because I&#8217;ve found no information on the web and think this could be useful for others as well. Caution: More often than not you only want to get the contents of an URL, for this simply use the following:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Blue;">NSString</span><span style="color: Gray;"> *</span><span style="color: Blue;">someString</span><span style="color: Gray;"> = </span><span style="color: Olive;">[</span><span style="color: Blue;">NSString</span><span style="color: Gray;"> </span><span style="color: Blue;">stringWithContentsOfURL</span><span style="color: Gray;">:</span><span style="color: Olive;">(</span><span style="color: Blue;">NSURL</span><span style="color: Gray;"> *</span><span style="color: Olive;">)</span><span style="color: Blue;">url</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></div></div>
<p>But if you in fact want to connect low level to a socket and read/write the bytes themselves you can get it running like this:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #ffa500;">// This will be the read stream.</span><span style="color: Gray;"><br /></span><span style="color: Blue;">CFReadStreamRef</span><span style="color: Gray;"> </span><span style="color: Blue;">myReadStream</span><span style="color: Gray;"> = </span><span class="hl-prepro">NULL</span><span style="color: Gray;">;<br />&nbsp;<br /></span><span style="color: #ffa500;">// This will be the write stream.</span><span style="color: Gray;"><br /></span><span style="color: Blue;">CFReadStreamRef</span><span style="color: Gray;"> </span><span style="color: Blue;">myWriteStream</span><span style="color: Gray;"> = </span><span class="hl-prepro">NULL</span><span style="color: Gray;">;<br />&nbsp;<br /></span><span style="color: #ffa500;">// Create socket.</span><span style="color: Gray;"><br /></span><span style="color: Blue;">CFStreamCreatePairWithSocketToHost</span><span style="color: Olive;">(</span><span style="color: Blue;">kCFAllocatorDefault</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">(</span><span style="color: Blue;">CFStringRef</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Blue;">yourHostAsNSString</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">yourPortAsInteger</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;</span><span style="color: Blue;">myReadStream</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;</span><span style="color: Blue;">myWriteStream</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;<br /></span><span style="color: #ffa500;">// Open read stream.</span><span style="color: Gray;"><br /></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">myReadStream</span><span style="color: Gray;"> != </span><span class="hl-prepro">NULL</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Blue;">CFReadStreamOpen</span><span style="color: Olive;">(</span><span style="color: Blue;">myReadStream</span><span style="color: Olive;">))</span><span style="color: Gray;"><br /></span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">// Read bytes in chunks of ten bytes.</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UInt8</span><span style="color: Gray;"> </span><span style="color: Blue;">readBuffer</span><span style="color: Olive;">[</span><span style="color: Maroon;">10</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">while</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">CFReadStreamHasBytesAvailable</span><span style="color: Olive;">(</span><span style="color: Blue;">stream</span><span style="color: Olive;">))</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">// Read bytes.</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">CFReadStreamRead</span><span style="color: Olive;">(</span><span style="color: Blue;">stream</span><span style="color: Gray;">, </span><span style="color: Blue;">buffer</span><span style="color: Gray;">, </span><span style="color: Maroon;">10</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">// Do something with your bytes ...</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: #ffa500;">// Open write stream.</span><span style="color: Gray;"><br /></span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">myWriteStream</span><span style="color: Gray;"> != </span><span class="hl-prepro">NULL</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Blue;">CFWriteStreamOpen</span><span style="color: Olive;">(</span><span style="color: Blue;">myWriteStream</span><span style="color: Olive;">))</span><span style="color: Gray;"><br /></span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: #ffa500;">// Write a byte.</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UInt8</span><span style="color: Gray;"> </span><span style="color: Blue;">writeBuffer</span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">writeBuffer</span><span style="color: Olive;">[</span><span style="color: Maroon;">0</span><span style="color: Olive;">]</span><span style="color: Gray;"> = </span><span style="color: Maroon;">42</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">CFWriteStreamWrite</span><span style="color: Olive;">(</span><span style="color: Blue;">stream</span><span style="color: Gray;">, </span><span style="color: Blue;">writeBuffer</span><span style="color: Gray;">, </span><span style="color: Maroon;">1</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: #ffa500;">// Be a good citizen.</span><span style="color: Gray;"><br /></span><span style="color: Blue;">CFReadStreamClose</span><span style="color: Olive;">(</span><span style="color: Blue;">myReadStream</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Blue;">CFWriteStreamClose</span><span style="color: Olive;">(</span><span style="color: Blue;">myWriteStream</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Blue;">CFRelease</span><span style="color: Olive;">(</span><span style="color: Blue;">myReadStream</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br /></span><span style="color: Blue;">CFRelease</span><span style="color: Olive;">(</span><span style="color: Blue;">myWriteStream</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/socket-communication-on-the-iphone-ipad/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPad类似Setting程序，竖屏SplitView小demo</title>
		<link>http://www.ieliwb.com/ipad-custom-split-view-application/</link>
		<comments>http://www.ieliwb.com/ipad-custom-split-view-application/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 01:44:41 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[setting]]></category>
		<category><![CDATA[UISplitViewController]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/?p=253</guid>
		<description><![CDATA[<p>竖屏SplitView，类似系统的setting程序，一个demo。<br />
看到cc很多人在问，发下。</p>
<p>效果：<br />
<a href="http://www.ieliwb.com/app/screenshot.php?s=iWebmasterHD"><img src="http://www.ieliwb.com/app/screenshot/iwebmasterhd/1.png" alt="" /></a></p>
<p>相关讨论：</p>
<p>http://www.cocoachina.com/bbs/read.php?tid-25636-page-1.html</p>
<p>这个讨论内容可能用的上(右边多个控制器相关)：</p>
<p>http:[......]</p><p class='read-more'><a href='http://www.ieliwb.com/ipad-custom-split-view-application/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>竖屏SplitView，类似系统的setting程序，一个demo。<br />
看到cc很多人在问，发下。</p>
<p>效果：<br />
<a href="http://www.ieliwb.com/app/screenshot.php?s=iWebmasterHD"><img src="http://www.ieliwb.com/app/screenshot/iwebmasterhd/1.png" alt="" /></a></p>
<p>相关讨论：</p>
<p>http://www.cocoachina.com/bbs/read.php?tid-25636-page-1.html</p>
<p>这个讨论内容可能用的上(右边多个控制器相关)：</p>
<p>http://www.cocoachina.com/bbs/read.php?tid-24466.html</p>
<p>源码demo：<br />
<a href="http://www.ieliwb.com/u/zip/MasterDetail.zip" target="_blank">下载</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/ipad-custom-split-view-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TCP中connect加入的超时控制</title>
		<link>http://www.ieliwb.com/tcp-connect-time-limit-out/</link>
		<comments>http://www.ieliwb.com/tcp-connect-time-limit-out/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 08:12:07 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[超时]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/tcp%e4%b8%adconnect%e5%8a%a0%e5%85%a5%e7%9a%84%e8%b6%85%e6%97%b6%e6%8e%a7%e5%88%b6/</guid>
		<description><![CDATA[<p>最近写iPad下iWebmaster中portscan用到的,备份记录下,大致核心部分如下:</p>
<p>在使用TCP的connect连接服务器时，在默认情况下系统使用的是阻塞式socket，如果服务器当前不可用，则connect会等待知道超时时间到达，而这个超时时间是系统内核规定的，并不能使用setSocke[......]</p><p class='read-more'><a href='http://www.ieliwb.com/tcp-connect-time-limit-out/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>最近写iPad下iWebmaster中portscan用到的,备份记录下,大致核心部分如下:</p>
<p>在使用TCP的connect连接服务器时，在默认情况下系统使用的是阻塞式socket，如果服务器当前不可用，则connect会等待知道超时时间到达，而这个超时时间是系统内核规定的，并不能使用setSocketOpt来设置，这个函数只能设置send和recv的超时，为了能够随意控制connect的超时时间，可以使用select。大致的过程就是先将socket设置成非阻塞，使用select去轮询套接口，再根据套接口去判断连接状态。</p>
<div class="hl-surround"><div class="hl-main"><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">flag</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">flag</span><span style="color: Gray;"> = </span><span style="color: Blue;">fcntl</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,</span><span style="color: Blue;">F_GETFL</span><span style="color: Gray;">,</span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">flag</span><span style="color: Gray;"> |= </span><span style="color: Blue;">O_NONBLOCK</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">fcntl</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,</span><span style="color: Blue;">F_SETFL</span><span style="color: Gray;">,</span><span style="color: Blue;">flag</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: #ffa500;">//设置非阻塞</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">type</span><span style="color: Gray;"> == </span><span style="color: Blue;">SOCK_STREAM</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">ret</span><span style="color: Gray;"> = -</span><span style="color: Maroon;">1</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">connected</span><span style="color: Gray;"> = </span><span style="color: Blue;">connect</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">, </span><span style="color: Olive;">(</span><span class="hl-types">struct</span><span style="color: Gray;"> </span><span style="color: Blue;">sockaddr</span><span style="color: Gray;"> *</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;</span><span style="color: Blue;">address</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">sizeof</span><span style="color: Olive;">(</span><span style="color: Blue;">address</span><span style="color: Olive;">))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">connected</span><span style="color: Gray;"> != </span><span style="color: Maroon;">0</span><span style="color: Gray;"> </span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: #ffa500;">//if 1</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">errno</span><span style="color: Gray;"> != </span><span style="color: Blue;">EINPROGRESS</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">logdown</span><span style="color: Olive;">(</span><span style="color: Blue;">ERROR</span><span style="color: Gray;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">connect error :%s</span><span style="color: Navy;">\</span><span style="color: Red;">n</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,</span><span style="color: Blue;">strerror</span><span style="color: Olive;">(</span><span style="color: Blue;">errno</span><span style="color: Olive;">))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: #ffa500;">//esle</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span class="hl-types">struct</span><span style="color: Gray;"> </span><span style="color: Blue;">timeval</span><span style="color: Gray;"> </span><span style="color: Blue;">tm</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">tm</span><span style="color: Gray;">.</span><span style="color: Blue;">tv_sec</span><span style="color: Gray;"> = </span><span style="color: Maroon;">3</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">tm</span><span style="color: Gray;">.</span><span style="color: Blue;">tv_usec</span><span style="color: Gray;"> = </span><span style="color: Maroon;">0</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">fd_set</span><span style="color: Gray;"> </span><span style="color: Blue;">set</span><span style="color: Gray;">,</span><span style="color: Blue;">rset</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">FD_ZERO</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: Blue;">set</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">FD_ZERO</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: Blue;">rset</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">FD_SET</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">set</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">FD_SET</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">rset</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">socklen_t</span><span style="color: Gray;"> </span><span style="color: Blue;">len</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">error</span><span style="color: Gray;"> = -</span><span style="color: Maroon;">1</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">res</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">res</span><span style="color: Gray;"> = </span><span style="color: Blue;">select</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">+</span><span style="color: Maroon;">1</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">rset</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">set</span><span style="color: Gray;">,</span><span class="hl-prepro">NULL</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">tm</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">res</span><span style="color: Gray;"> &lt; </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">logdown</span><span style="color: Olive;">(</span><span style="color: Blue;">WARNNING</span><span style="color: Gray;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">network error in connect</span><span style="color: Navy;">\</span><span style="color: Red;">n</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">ret</span><span style="color: Gray;"> =&nbsp; -</span><span style="color: Maroon;">1</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">res</span><span style="color: Gray;"> == </span><span style="color: Maroon;">0</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">logdown</span><span style="color: Olive;">(</span><span style="color: Blue;">WARNNING</span><span style="color: Gray;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">connect time out</span><span style="color: Navy;">\</span><span style="color: Red;">n</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">ret</span><span style="color: Gray;"> = -</span><span style="color: Maroon;">2</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Green;">if</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Maroon;">1</span><span style="color: Gray;"> == </span><span style="color: Blue;">res</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">FD_ISSET</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,&amp;</span><span style="color: Blue;">set</span><span style="color: Olive;">))</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">flag</span><span style="color: Gray;"> &amp;= ~</span><span style="color: Blue;">O_NONBLOCK</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">fcntl</span><span style="color: Olive;">(</span><span style="color: Blue;">sock</span><span style="color: Gray;">,</span><span style="color: Blue;">F_SETFL</span><span style="color: Gray;">,</span><span style="color: Blue;">flag</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span><span style="color: #ffa500;">//设置阻塞</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">sock</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">ret</span><span style="color: Gray;"> = -</span><span style="color: Maroon;">3</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">logdown</span><span style="color: Olive;">(</span><span style="color: Blue;">WARNNING</span><span style="color: Gray;">,</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">other error when select:%s</span><span style="color: Navy;">\</span><span style="color: Red;">n</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,</span><span style="color: Blue;">strerror</span><span style="color: Olive;">(</span><span style="color: Blue;">errno</span><span style="color: Olive;">))</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">ret</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: #ffa500;">//else </span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: #ffa500;">//if 1</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">return</span><span style="color: Gray;"> </span><span style="color: Blue;">sock</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span></div></div>
<p>程序先把socket设置成非阻塞，connect在非阻塞模式下会立刻返回，如果没有其他错误，返回值等于0。当connect不能立刻建立连接时，会返回一个EINPROGRESS，表示连接正在建立的过程中，这时我们可以使用select去轮询套接口，而select的轮询超时时间可以根据自己的需要去设置，最主要的是轮询的集合一定要是读和写的集合，即select的第二和第三个参数要赋值，待select返回就可以去判断返回值来确定connect的进程状态了。如果返回值小于0，说明connect的进程出现了错误，如果是等于0则说明connect超时，如果等于1，并且套接口此时的状态是可写，则说明了connect已经成功建立（关于这点大概是因为服务器接收了连接后，不会立刻想socket写数据，这是客户端就只能轮询到可写的socket，我觉得如果服务器接受连接并立刻写数据，在客户端就可能是返回2，这时学要同时判断socket的可读和可写了）；其他情况的话就算是其他错误吧，至此，我们只需要设置select的超时值就可以随心所欲地实现自己想要的connect连接超时了。</p>
<p>    最后，别忘了把套接口设置会阻塞状态，毕竟阻塞状态加线程方便控制。</p>
<p>效果图:<a href="www.ieliwb.com/app/screenshot.php?s=iWebmasterHD">www.ieliwb.com/app/screenshot.php?s=iWebmasterHD</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/tcp-connect-time-limit-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我会一直用心做好产品,做好服务的</title>
		<link>http://www.ieliwb.com/itoolhd-ipad-top-paid/</link>
		<comments>http://www.ieliwb.com/itoolhd-ipad-top-paid/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 13:36:21 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[心情随笔/生活感悟]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iTool]]></category>
		<category><![CDATA[生活查询]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/%e6%88%91%e4%bc%9a%e4%b8%80%e7%9b%b4%e7%94%a8%e5%bf%83%e5%81%9a%e5%a5%bd%e4%ba%a7%e5%93%81%e5%81%9a%e5%a5%bd%e6%9c%8d%e5%8a%a1%e7%9a%84/</guid>
		<description><![CDATA[<p>偶的生活查询for iPad 上线3天登上了中国区付费棒首,小小的祝贺一下.我会一直用心做好产品,做好服务的,感谢Apple,感谢AppStore,感谢所有Apple fans.</p>
<p><img src="http://www.ieliwb.com/u/img/ipad-top-paid.jpg" alt="" /></p>
<p><a href="http://www.ieliwb.com/app/iToolHD.html">生活查询for iPad</a><br />
<a href="http://www.ieliwb.com/app/iTool.html">生活查询for iPhone</a></p>]]></description>
			<content:encoded><![CDATA[<p>偶的生活查询for iPad 上线3天登上了中国区付费棒首,小小的祝贺一下.我会一直用心做好产品,做好服务的,感谢Apple,感谢AppStore,感谢所有Apple fans.</p>
<p><img src="http://www.ieliwb.com/u/img/ipad-top-paid.jpg" alt="" /></p>
<p><a href="http://www.ieliwb.com/app/iToolHD.html">生活查询for iPad</a><br />
<a href="http://www.ieliwb.com/app/iTool.html">生活查询for iPhone</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/itoolhd-ipad-top-paid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不同控制器之间通信的一个好方法</title>
		<link>http://www.ieliwb.com/nsnotification-observer-communicate/</link>
		<comments>http://www.ieliwb.com/nsnotification-observer-communicate/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 09:48:14 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[NSNotificationCenter]]></category>
		<category><![CDATA[观察者模式]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/%e4%b8%8d%e5%90%8c%e6%8e%a7%e5%88%b6%e5%99%a8%e4%b9%8b%e9%97%b4%e9%80%9a%e4%bf%a1%e7%9a%84%e4%b8%80%e4%b8%aa%e5%a5%bd%e6%96%b9%e6%b3%95/</guid>
		<description><![CDATA[<p>首页在view1的控制器初始化init方法里加上观察者模式方法:</p>
<blockquote><p>
[[NSNotificationCenter defaultCenter] addObserver:self<br />
												 selector:@selector(reloadChat:)<br />
													 na[......]</p></blockquote><p class='read-more'><a href='http://www.ieliwb.com/nsnotification-observer-communicate/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>首页在view1的控制器初始化init方法里加上观察者模式方法:</p>
<blockquote><p>
[[NSNotificationCenter defaultCenter] addObserver:self<br />
												 selector:@selector(reloadChat:)<br />
													 name:@&#8221;reloadChat&#8221; object:nil];
</p></blockquote>
<blockquote><p>
-(void)reloadChat:(id)sender{}
</p></blockquote>
<hr/>
<p>在view2里的button添加用来触发view1的reloadChat方法:	</p>
<blockquote><p>
[[NSNotificationCenter defaultCenter] postNotificationName:@&#8221;reloadChat&#8221; object:self];
</p></blockquote>
<p>&#8212;END&#8212;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/nsnotification-observer-communicate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>一代二代iPhone千万别升级到iOS4.0,警惕!!!!</title>
		<link>http://www.ieliwb.com/iphone-3g-to-ios4-lazy/</link>
		<comments>http://www.ieliwb.com/iphone-3g-to-ios4-lazy/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 14:52:48 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[心情随笔/生活感悟]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/%e4%b8%80%e4%bb%a3%e4%ba%8c%e4%bb%a3iphone%e5%8d%83%e4%b8%87%e5%88%ab%e5%8d%87%e7%ba%a7%e5%88%b0ios4-0%e8%ad%a6%e6%83%95/</guid>
		<description><![CDATA[偶二代机器就是一个活生生的例子,升级后卡的滴血.偶现在每天都运行在安全模式,正常模式放个音乐都卡的吐血......

<img src="http://www.ieliwb.com/u/img/iphone-4.0-screen-1.jpg" alt="" />

后台运行就是个大垃圾,还没以前的插件好用.....

痛苦......
痛苦......
鸡肋......
鸡肋......
纠结......[......]<p class='read-more'><a href='http://www.ieliwb.com/iphone-3g-to-ios4-lazy/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>偶二代机器就是一个活生生的例子,升级后卡的滴血.偶现在每天都运行在安全模式,正常模式放个音乐都卡的吐血&#8230;&#8230;</p>
<p><img src="http://www.ieliwb.com/u/img/iphone-4.0-screen-1.jpg" alt="" /><br />
<img src="http://www.ieliwb.com/u/img/iphone-4.0-screen-2.jpg" alt="" /></p>
<p>后台运行就是个大垃圾,还没以前的插件好用&#8230;..</p>
<p>痛苦&#8230;&#8230;<br />
鸡肋&#8230;&#8230;<br />
鸡肋&#8230;&#8230;<br />
纠结&#8230;&#8230;</p>
<p>有视频为证:</p>
<p><embed src="http://player.youku.com/player.php/sid/XMTkzNTg2NjYw/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/iphone-3g-to-ios4-lazy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>没有ipad,发布真机截图的几个方法</title>
		<link>http://www.ieliwb.com/no-ipad-screenshot-methods/</link>
		<comments>http://www.ieliwb.com/no-ipad-screenshot-methods/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 13:05:46 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/%e6%b2%a1%e6%9c%89ipad%e5%8f%91%e5%b8%83%e7%9c%9f%e6%9c%ba%e6%88%aa%e5%9b%be%e7%9a%84%e5%87%a0%e4%b8%aa%e6%96%b9%e6%b3%95/</guid>
		<description><![CDATA[<p>1.CTRL+COMMAND+C,然后在Preview里New from clipboard(不带边框,推荐)</p>
<p>2.cmd＋shift＋4，这时按下空格就会出现相机窗口选择,点一下模拟器就可以(带边框)</p>]]></description>
			<content:encoded><![CDATA[<p>1.CTRL+COMMAND+C,然后在Preview里New from clipboard(不带边框,推荐)</p>
<p>2.cmd＋shift＋4，这时按下空格就会出现相机窗口选择,点一下模拟器就可以(带边框)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/no-ipad-screenshot-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone的九宫格实现代码</title>
		<link>http://www.ieliwb.com/iphone-nine-box/</link>
		<comments>http://www.ieliwb.com/iphone-nine-box/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 04:45:31 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[九宫格]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/iphone%e7%9a%84%e4%b9%9d%e5%ae%ab%e6%a0%bc%e5%ae%9e%e7%8e%b0%e4%bb%a3%e7%a0%81/</guid>
		<description><![CDATA[<p>看到CocoaChina很多同学在问,其实很简单,我这是用图片堆砌实现的九宫格,分享如下:</p>
<p>效果图:<br />
<img src="http://www.ieliwb.com/u/img/iphone-9-gong-ge.jpg" alt="" /></p>
<p>核心就这2个方法:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #ffa500;">//Power by ieliwb.com</span><span style="color: Gray;"><br />- </span><span style="color: Olive;">(</span><span class="hl-types">void</span><span style="color: Olive;">)</span><span style="color: Blue;">viewDidLoad</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&#160;&#160; &#160;</span><span style="color: Olive;">[</span><span style="color: Blue;">super</span><span style="color: Gray;"> </span><span style="color: Blue;">viewDidLoad</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&#160;&#038;[......]</span></div></div><p class='read-more'><a href='http://www.ieliwb.com/iphone-nine-box/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>看到CocoaChina很多同学在问,其实很简单,我这是用图片堆砌实现的九宫格,分享如下:</p>
<p>效果图:<br />
<img src="http://www.ieliwb.com/u/img/iphone-9-gong-ge.jpg" alt="" /></p>
<p>核心就这2个方法:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #ffa500;">//Power by ieliwb.com</span><span style="color: Gray;"><br />- </span><span style="color: Olive;">(</span><span class="hl-types">void</span><span style="color: Olive;">)</span><span style="color: Blue;">viewDidLoad</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">super</span><span style="color: Gray;"> </span><span style="color: Blue;">viewDidLoad</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">NSArray</span><span style="color: Gray;">* </span><span style="color: Blue;">imageNames</span><span style="color: Gray;"> = </span><span style="color: Olive;">[</span><span style="color: Blue;">NSArray</span><span style="color: Gray;"> </span><span style="color: Blue;">arrayWithObjects</span><span style="color: Gray;">:<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_mobile.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_idcard.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_postcode.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_flight.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_translate.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_phone.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_car.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_health.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, <br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">ico_bjxm.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">nil</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UIButton</span><span style="color: Gray;"> *</span><span style="color: Blue;">Btn</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">for</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">i</span><span style="color: Gray;">=</span><span style="color: Maroon;">0</span><span style="color: Gray;">; </span><span style="color: Blue;">i</span><span style="color: Gray;">&lt;</span><span style="color: Maroon;">9</span><span style="color: Gray;">; </span><span style="color: Blue;">i</span><span style="color: Gray;">++</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">CGRect</span><span style="color: Gray;"> </span><span style="color: Blue;">frame</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> = </span><span style="color: Olive;">[[</span><span style="color: Blue;">UIButton</span><span style="color: Gray;"> </span><span style="color: Blue;">buttonWithType</span><span style="color: Gray;">:</span><span style="color: Blue;">UIButtonTypeCustom</span><span style="color: Olive;">]</span><span style="color: Gray;"> </span><span style="color: Blue;">retain</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> </span><span style="color: Blue;">setImage</span><span style="color: Gray;">:</span><span style="color: Olive;">[</span><span style="color: Blue;">UIImage</span><span style="color: Gray;"> </span><span style="color: Blue;">imageNamed</span><span style="color: Gray;">:</span><span style="color: Olive;">[</span><span style="color: Blue;">imageNames</span><span style="color: Gray;"> </span><span style="color: Blue;">objectAtIndex</span><span style="color: Gray;">: </span><span style="color: Blue;">i</span><span style="color: Olive;">]]</span><span style="color: Gray;"> </span><span style="color: Blue;">forState</span><span style="color: Gray;">:</span><span style="color: Blue;">UIControlStateNormal</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span><span style="color: #ffa500;">//设置按钮图片</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">Btn</span><span style="color: Gray;">.</span><span style="color: Blue;">tag</span><span style="color: Gray;"> = </span><span style="color: Blue;">i</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">size</span><span style="color: Gray;">.</span><span style="color: Blue;">width</span><span style="color: Gray;"> = </span><span style="color: Maroon;">59</span><span style="color: Gray;">;</span><span style="color: #ffa500;">//设置按钮坐标及大小</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">size</span><span style="color: Gray;">.</span><span style="color: Blue;">height</span><span style="color: Gray;"> = </span><span style="color: Maroon;">75</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">origin</span><span style="color: Gray;">.</span><span style="color: Blue;">x</span><span style="color: Gray;"> = </span><span style="color: Olive;">(</span><span style="color: Blue;">i</span><span style="color: Gray;">%</span><span style="color: Maroon;">3</span><span style="color: Olive;">)</span><span style="color: Gray;">*</span><span style="color: Olive;">(</span><span style="color: Maroon;">59</span><span style="color: Gray;">+</span><span style="color: Maroon;">32</span><span style="color: Olive;">)</span><span style="color: Gray;">+</span><span style="color: Maroon;">40</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">origin</span><span style="color: Gray;">.</span><span style="color: Blue;">y</span><span style="color: Gray;"> = </span><span style="color: Blue;">floor</span><span style="color: Olive;">(</span><span style="color: Blue;">i</span><span style="color: Gray;">/</span><span style="color: Maroon;">3</span><span style="color: Olive;">)</span><span style="color: Gray;">*</span><span style="color: Olive;">(</span><span style="color: Maroon;">75</span><span style="color: Gray;">+</span><span style="color: Maroon;">24</span><span style="color: Olive;">)</span><span style="color: Gray;">+</span><span style="color: Maroon;">40</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> </span><span style="color: Blue;">setFrame</span><span style="color: Gray;">:</span><span style="color: Blue;">frame</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> </span><span style="color: Blue;">setBackgroundColor</span><span style="color: Gray;">:</span><span style="color: Olive;">[</span><span style="color: Blue;">UIColor</span><span style="color: Gray;"> </span><span style="color: Blue;">clearColor</span><span style="color: Olive;">]]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> </span><span style="color: Blue;">addTarget</span><span style="color: Gray;">:</span><span style="color: Blue;">self</span><span style="color: Gray;"> </span><span style="color: Blue;">action</span><span style="color: Gray;">:@</span><span style="color: Blue;">selector</span><span style="color: Olive;">(</span><span style="color: Blue;">btnPressed</span><span style="color: Gray;">:</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Blue;">forControlEvents</span><span style="color: Gray;">:</span><span style="color: Blue;">UIControlEventTouchUpInside</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">self</span><span style="color: Gray;">.</span><span style="color: Blue;">view</span><span style="color: Gray;"> </span><span style="color: Blue;">addSubview</span><span style="color: Gray;">:</span><span style="color: Blue;">Btn</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> </span><span style="color: Blue;">release</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: #ffa500;">//响应按钮事件</span><span style="color: Gray;"><br />-</span><span style="color: Olive;">(</span><span class="hl-types">void</span><span style="color: Olive;">)</span><span style="color: Blue;">btnPressed</span><span style="color: Gray;">:</span><span style="color: Olive;">(</span><span style="color: Blue;">id</span><span style="color: Olive;">)</span><span style="color: Blue;">sender</span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UIButton</span><span style="color: Gray;"> *</span><span style="color: Blue;">Btn</span><span style="color: Gray;"> = </span><span style="color: Olive;">(</span><span style="color: Blue;">UIButton</span><span style="color: Gray;"> *</span><span style="color: Olive;">)</span><span style="color: Blue;">sender</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">index</span><span style="color: Gray;"> = </span><span style="color: Blue;">Btn</span><span style="color: Gray;">.</span><span style="color: Blue;">tag</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Green;">switch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">index</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">case</span><span style="color: Gray;"> </span><span style="color: Maroon;">0</span><span style="color: Gray;">:<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">if</span><span style="color: Olive;">(</span><span style="color: Blue;">mobileController</span><span style="color: Gray;">==</span><span style="color: Blue;">nil</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Blue;">mobileController</span><span style="color: Gray;"> = </span><span style="color: Olive;">[[</span><span style="color: Blue;">MobileController</span><span style="color: Gray;"> </span><span style="color: Blue;">alloc</span><span style="color: Olive;">]</span><span style="color: Blue;">init</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">self</span><span style="color: Gray;">.</span><span style="color: Blue;">navigationController</span><span style="color: Gray;"> </span><span style="color: Blue;">pushViewController</span><span style="color: Gray;">:</span><span style="color: Blue;">mobileController</span><span style="color: Gray;"> </span><span style="color: Blue;">animated</span><span style="color: Gray;">:</span><span style="color: Blue;">YES</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: Green;">break</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: #ffa500;">//其他几个控制器类似</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">}</span><span style="color: Gray;"><br />&nbsp;<br /></span><span style="color: Olive;">}</span></div></div>
<p>九宫格背景修改可以这样实现:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Gray;">- </span><span style="color: Olive;">(</span><span class="hl-types">void</span><span style="color: Olive;">)</span><span style="color: Blue;">loadView</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UIImageView</span><span style="color: Gray;"> *</span><span style="color: Blue;">contentView</span><span style="color: Gray;"> = </span><span style="color: Olive;">[[</span><span style="color: Blue;">UIImageView</span><span style="color: Gray;"> </span><span style="color: Blue;">alloc</span><span style="color: Olive;">]</span><span style="color: Gray;"> </span><span style="color: Blue;">initWithFrame</span><span style="color: Gray;">:</span><span style="color: Olive;">[[</span><span style="color: Blue;">UIScreen</span><span style="color: Gray;"> </span><span style="color: Blue;">mainScreen</span><span style="color: Olive;">]</span><span style="color: Gray;"> </span><span style="color: Blue;">applicationFrame</span><span style="color: Olive;">]]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">contentView</span><span style="color: Gray;"> </span><span style="color: Blue;">setImage</span><span style="color: Gray;">:</span><span style="color: Olive;">[</span><span style="color: Blue;">UIImage</span><span style="color: Gray;"> </span><span style="color: Blue;">imageNamed</span><span style="color: Gray;">:@</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">subview_9_bg.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">]]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">contentView</span><span style="color: Gray;"> </span><span style="color: Blue;">setUserInteractionEnabled</span><span style="color: Gray;">:</span><span style="color: Blue;">YES</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">self</span><span style="color: Gray;">.</span><span style="color: Blue;">view</span><span style="color: Gray;"> = </span><span style="color: Blue;">contentView</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">contentView</span><span style="color: Gray;"> </span><span style="color: Blue;">release</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br /></span><span style="color: Olive;">}</span></div></div>
<p>UINavigationBar背景图片可以这样实现:</p>
<div class="hl-surround"><div class="hl-main"><span style="color: Gray;">@</span><span style="color: Blue;">implementation</span><span style="color: Gray;"> </span><span style="color: Blue;">UINavigationBar</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">CustomImage</span><span style="color: Olive;">)</span><span style="color: Gray;"><br />- </span><span style="color: Olive;">(</span><span class="hl-types">void</span><span style="color: Olive;">)</span><span style="color: Blue;">drawRect</span><span style="color: Gray;">:</span><span style="color: Olive;">(</span><span style="color: Blue;">CGRect</span><span style="color: Olive;">)</span><span style="color: Blue;">rect</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span><span style="color: Gray;"><br />&nbsp;&nbsp; &nbsp;</span><span style="color: Blue;">UIImage</span><span style="color: Gray;"> *</span><span style="color: Blue;">image</span><span style="color: Gray;"> = </span><span style="color: Olive;">[</span><span style="color: Blue;">UIImage</span><span style="color: Gray;"> </span><span style="color: Blue;">imageNamed</span><span style="color: Gray;">: @</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">top_bg.png</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">]</span><span style="color: Gray;">;<br />&nbsp;&nbsp; &nbsp;</span><span style="color: Olive;">[</span><span style="color: Blue;">image</span><span style="color: Gray;"> </span><span style="color: Blue;">drawInRect</span><span style="color: Gray;">:</span><span style="color: Blue;">CGRectMake</span><span style="color: Olive;">(</span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: Blue;">self</span><span style="color: Gray;">.</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">size</span><span style="color: Gray;">.</span><span style="color: Blue;">width</span><span style="color: Gray;">, </span><span style="color: Blue;">self</span><span style="color: Gray;">.</span><span style="color: Blue;">frame</span><span style="color: Gray;">.</span><span style="color: Blue;">size</span><span style="color: Gray;">.</span><span style="color: Blue;">height</span><span style="color: Olive;">)]</span><span style="color: Gray;">;<br /></span><span style="color: Olive;">}</span><span style="color: Gray;"><br />@</span><span style="color: Blue;">end</span></div></div>
<p>&#8212;-End&#8212;-</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/iphone-nine-box/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AppStore的Review效率&#8230;&#8230;</title>
		<link>http://www.ieliwb.com/appstore-review-efficiency/</link>
		<comments>http://www.ieliwb.com/appstore-review-efficiency/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 04:08:33 +0000</pubDate>
		<dc:creator>花太香齐</dc:creator>
				<category><![CDATA[iPhone/Mac/ObjectC]]></category>
		<category><![CDATA[心情随笔/生活感悟]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[reject]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://www.ieliwb.com/?p=245</guid>
		<description><![CDATA[<p><img src="http://www.ieliwb.com/u/img/appstore-review.jpg" width="600" alt="" /></p>
<p>原因:</p>
<blockquote><p>第一次:rewrite了私有api   (苹果就是霸王,有些api只能自己用,还不让人改)<br />
第二次:请提供用户名和密码测试,我日,(注册就在登录下面)<br />
第三次:有彩票 (彩票的最好一律不要做了)<br />
第四次:简介里有彩票  (连软件说明简介都要注意)
</p></blockquote>
<p><strong>现在审查很慢很严格。而且，apple那里[......]</strong></p><p class='read-more'><a href='http://www.ieliwb.com/appstore-review-efficiency/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ieliwb.com/u/img/appstore-review.jpg" width="600" alt="" /></p>
<p>原因:</p>
<blockquote><p>第一次:rewrite了私有api   (苹果就是霸王,有些api只能自己用,还不让人改)<br />
第二次:请提供用户名和密码测试,我日,(注册就在登录下面)<br />
第三次:有彩票 (彩票的最好一律不要做了)<br />
第四次:简介里有彩票  (连软件说明简介都要注意)
</p></blockquote>
<p><strong>现在审查很慢很严格。而且，apple那里似乎也没有个不允许使用东西的列表,这应该是让我们开发者更加的注意自己的程序，不然被拒后再提交要花费很长时间.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ieliwb.com/appstore-review-efficiency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
