<?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>Jeffrey Sambells &#187; XCode</title>
	<atom:link href="http://jeffreysambells.com/category/xcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeffreysambells.com</link>
	<description>Geek out AFK</description>
	<lastBuildDate>Mon, 14 May 2012 16:04:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>&#9734; More on Bloat</title>
		<link>http://jeffreysambells.com/posts/2012/03/19/more-on-bloat/</link>
		<comments>http://jeffreysambells.com/posts/2012/03/19/more-on-bloat/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 14:27:06 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Resolutions]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1615</guid>
		<description><![CDATA[The other day I talked about the retina display bloat and using vectors to vastly decrease the distribution size of your iOS apps. The drawback however was that it only work for image that can be vectorized. So what about the rest of your images like photos or the default screens? Well, it turns out [...]<p><a href="http://jeffreysambells.com/posts/2012/03/19/more-on-bloat/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>The other day I talked about the retina display bloat and <a href="http://jeffreysambells.com/posts/2012/03/02/beating-the-20mb-size-limit-ipad-retina-displays/">using vectors to vastly decrease the distribution size of your iOS apps</a>. The drawback however was that it only work for image that can be vectorized. So what about the rest of your images like photos or the default screens?</p>

<p>Well, it turns out that the built-in Xcode PNG compression tool kinda lacks in the compression department. There&#8217;s a <a href="http://imageoptim.com/tweetbot.html">great case study</a> about the Tweetbot app over on the ImageOptimum site:</p>

<blockquote>
  <p>Disabling Xcode conversion and simply using ImageOptim instead was enough to reduce the application size by almost 30% (33.4MB down to 23.8MB) and halve initial display time.</p>
  
  <p>Manually optimizing images with ImageAlpha reduced entire application size by more than a half (33.4MB down to 16.3MB). Images alone were 65% smaller and were displayed 2.5 times quicker than Xcode-optimized ones.</p>
</blockquote>

<p>Now that&#8217;s awesome. If a few clicks can save you megabytes why not?</p>

<p>It turns out that Xcode creates a CgBI PNG varient optimized for loading speed using 32-bit BGRA. Jeff LaMarche has <a href="http://iphonedevelopment.blogspot.ca/2008/10/iphone-optimized-pngs.html">a great technical explanation</a> of what&#8217;s going on, explaining that Xcode basically optimizes for loading speed by swapping bytes in the image and &#8220;corrupting&#8221; the PNG format.</p>

<blockquote>
  <p>During the build, Xcode basically screws up your PNG image, turning it into something that&#8217;s technically no longer a PNG image. Xcode doesn&#8217;t change your original file, but when it copies it to the Resources folder of your application bundle, what it does is it byte-swaps the red and blue octets and also &#8220;premultiplies the alpha&#8221; &#8230; The PNG specification does not support either of these changes</p>
</blockquote>

<p>The other downside is that sometimes this manipulation results in a <em>larger</em> file size than you would have with a normally optimized PNG.</p>

<p>To disable Xcode&#8217;s built in image compression, go to your target&#8217;s build settings, filter for &#8220;Compress PNG Files&#8221; and select NO.</p>

<p>However, be cautious if you choose to disable Xcode&#8217;s built-in PNG optimization and do the optimization yourself with a tool like <a href="http://imageoptim.com/">ImageOptimum</a>. Disabling Xcode&#8217;s optimization will mean your iDevice will do the equivalent optimization on-the-fly at run-time, adding additional processing and memory overhead. You should to take this into consideration and optimize your code to share and reuse image resources where possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2012/03/19/more-on-bloat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; How to determine iOS device orientation when your app starts up.</title>
		<link>http://jeffreysambells.com/posts/2011/09/22/how-to-determine-ios-device-orientation-when-your-app-starts-up/</link>
		<comments>http://jeffreysambells.com/posts/2011/09/22/how-to-determine-ios-device-orientation-when-your-app-starts-up/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 03:18:51 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1295</guid>
		<description><![CDATA[I&#8217;ve been working on several iPad apps lately that require a loading screen to appear right after launch. All the apps are designed to work in any rotation so getting things to startup in the correct orientation has been a challenge because of some iOS &#8220;bugs&#8221; with device orientation at startup. After several attempts of [...]<p><a href="http://jeffreysambells.com/posts/2011/09/22/how-to-determine-ios-device-orientation-when-your-app-starts-up/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on several iPad apps lately that require a loading screen to appear right after launch. All the apps are designed to work in any rotation so getting things to startup in the correct orientation has been a challenge because of some <a href="http://openradar.appspot.com/7216046">iOS &#8220;bugs&#8221; with device orientation at startup</a>.</p>

<p>After several attempts of trial and error I believe the following is a foolproof solution for setting the correct orientation of the startup view for an iPad app (assuming the default view was design in portrait orientation). I thought I&#8217;d share it here for anyone else who is having a similar problem.</p>

<p>First, in <code>application:didFinishLaunchingWithOptions:</code> add the following:</p>

<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

   // The rest of your code...

}
</code></pre>

<p>then, on the view you want to rotate, check both interface and device orientation to properly position the view in all four orientations (plus laying flat on a table).</p>

<p>-(void)updateOrientation {</p>

<pre><code>    UIInterfaceOrientation iOrientation = [UIApplication sharedApplication].statusBarOrientation;
    UIDeviceOrientation dOrientation = [UIDevice currentDevice].orientation;

    bool landscape;

    if (dOrientation == UIDeviceOrientationUnknown || dOrientation == UIDeviceOrientationFaceUp || dOrientation == UIDeviceOrientationFaceDown) {
        // If the device is laying down, use the UIInterfaceOrientation based on the status bar.
        landscape = UIInterfaceOrientationIsLandscape(iOrientation);
    } else {
        // If the device is not laying down, use UIDeviceOrientation.
        landscape = UIDeviceOrientationIsLandscape(dOrientation);

        // There's a bug in iOS!!!! http://openradar.appspot.com/7216046
        // So values needs to be reversed for landscape!
        if (dOrientation == UIDeviceOrientationLandscapeLeft) iOrientation = UIInterfaceOrientationLandscapeRight;
        else if (dOrientation == UIDeviceOrientationLandscapeRight) iOrientation = UIInterfaceOrientationLandscapeLeft;

        else if (dOrientation == UIDeviceOrientationPortrait) iOrientation = UIInterfaceOrientationPortrait;
        else if (dOrientation == UIDeviceOrientationPortraitUpsideDown) iOrientation = UIInterfaceOrientationPortraitUpsideDown;
    }

    if (landscape) {
        // Do stuff for landscape mode.
    } else {
        // Do stuff for portrait mode.
    }

    // Now manually rotate the view if needed.
    switch (iOrientation) 
    {
        case UIInterfaceOrientationPortraitUpsideDown:
            [self rotate:180.0f];
            break;
        case UIInterfaceOrientationLandscapeRight:
            [self rotate:90.0f];
            break;
        case UIInterfaceOrientationLandscapeLeft:
            [self rotate:-90.0f];
            break;
        case UIInterfaceOrientationPortrait:
            break; //do nothing because it's fine
        default:
            break;
    }

    // Set the status bar to the right spot just in case
    [[UIApplication sharedApplication] setStatusBarOrientation:iOrientation];

}
</code></pre>

<p>Enjoy. If you found it useful or have an improvement, <a href="/contact">let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/09/22/how-to-determine-ios-device-orientation-when-your-app-starts-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; iOS Wireless App Distribution [Updated]</title>
		<link>http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/</link>
		<comments>http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 02:11:05 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=677</guid>
		<description><![CDATA[UPDATE: There&#8217;s been a lot of interest in this post and Ad Hoc distribution methods. This is a very simple example so if you&#8217;re looking for an off-the-shelf solution, I suggest you check out testflightapp.com or Hockey which provide more robust features. With the new iPhone iOS 4, you can distribute apps wirelessly without iTunes [...]<p><a href="http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p><em>UPDATE: There&#8217;s been a lot of interest in this post and Ad Hoc distribution methods. This is a very simple example so if you&#8217;re looking for an off-the-shelf solution, I suggest you check out <a href="http://testflightapp.com">testflightapp.com</a> or <a href="https://github.com/TheRealKerni/Hockey">Hockey</a> which provide more robust features.</em></p>

<p>With the new iPhone iOS 4, you can distribute apps wirelessly <em>without</em> iTunes intervention. You still need to collect the appropriate devices id&#8217;s and create the appropriate provisioning profiles but if you already have those sending out files is easy.</p>

<p>First, select &#8220;Build and Archive&#8221; from your XCode build menu. Your archived project will be stored in the &#8220;Archived Applications&#8221; section of the the XCode organizer (Window > Organizer).</p>

<p>Next, select the archive you want to distribute in the XCode organizer and select &#8220;Share Application&#8230;&#8221; at the bottom of the window. Pick the appropriate provisioning profile and then &#8220;Distribute for Enterprise&#8221;.</p>

<p>In the distribution window, enter the title and the full url to the <code>ipa</code> file (where you plan to host your app) for example, http://jeffreysambells.com/example.ipa.</p>

<p>Along with the generated .plist and the .ipa files, you&#8217;ll need the provisioning profile and a simple index file, for example:</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Cool app&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://jeffreysambells.com/example.mobileprovision"&gt;
                Install Example Provisioning File&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="itms-services://?action=download-manifest&amp;url=http://jeffreysambells.com/example.plist"&gt;
                Install Example Application&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>With these all uploaded to your server all you need to do is point people at the index file and they can select the links to install the provisioning profile and app directly from mobile safari on their iOS devices. A much nicer experience compared to installing through the iTunes sync process.</p>

<p><strong>UPDATE</strong></p>

<p>After re-publishing updates to my apps several times, I was finding it a little tedious to re-type the full url into the XCode tool&#8212;plus I could never remember what I named the damn files&#8212;so I came up with this quick and dirty <code>index.php</code> script to do the grunt work for me:</p>

<pre><code>&lt;?php

$ipas = glob('*.ipa');
$provisioningProfiles = glob('*.mobileprovision');
$plists = glob('*.plist');

$sr = stristr( $_SERVER['SCRIPT_URI'], '.php' ) === false ? 
    $_SERVER['SCRIPT_URI'] : dirname($_SERVER['SCRIPT_URI']) . '/';
$provisioningProfile = $sr . $provisioningProfiles[0];
$ipa = $sr . $ipas[0];
$itmsUrl = urlencode( $sr . 'index.php?plist=' . str_replace( '.plist', '', $plists[0] ) );


if ($_GET['plist']) {
    $plist = file_get_contents( dirname(__FILE__) 
        . DIRECTORY_SEPARATOR 
        . preg_replace( '/![A-Za-z0-9-_]/i', '', $_GET['plist']) . '.plist' );
    $plist = str_replace('_URL_', $ipa, $plist);
    header('content-type: application/xml');
    echo $plist;
    die();
}


?&gt;&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Install iOS App&lt;/title&gt;
&lt;style type="text/css"&gt;

li {
    padding: 1em;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="&lt;? echo $provisioningProfile; ?&gt;"&gt;Install Team Provisioning File&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="itms-services://?action=download-manifest&amp;url=&lt;? echo $itmsUrl; ?&gt;"&gt;
         Install Application&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>It&#8217;s nothing fancy so you&#8217;ll probably want to spiff it up but to use it (you&#8217;ll need PHP), just create a folder and drop in the <code>index.php</code> along with the <code>.mobileprovision</code> file, the exported <code>.ipa</code> and the exported <code>.plist</code>. To make things easy just enter <code>_URL_</code> (uppercase url with underscores) as the &#8220;url&#8221; in XCode and the script will automatically fill in the proper URL as necessary. It doesn&#8217;t matter what the file names are as long as there is only one <code>.moblieprovision</code>, <code>.ipa</code> and <code>.plist</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/06/22/ios-wireless-app-distribution/feed/</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
		<item>
		<title>&#9734; Dissecting iPhone OS Touch Actions for Text</title>
		<link>http://jeffreysambells.com/posts/2010/04/30/dissecting-iphone-os-touch-actions-for-text/</link>
		<comments>http://jeffreysambells.com/posts/2010/04/30/dissecting-iphone-os-touch-actions-for-text/#comments</comments>
		<pubDate>Sat, 01 May 2010 01:41:18 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[UITextInput]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=615</guid>
		<description><![CDATA[I&#8217;ve been working my way through a UiTextInput rich text editor implementation in iPhone OS 3.2 and thought I&#8217;d share some observations I&#8217;ve made regarding touch input related to text. One of the biggest hurdles with UiTextInput is that you don&#8217;t get the benefit of the great UI work that Apple has put in their [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working my way through a UiTextInput rich text editor implementation in iPhone OS 3.2 and thought I&#8217;d share some observations I&#8217;ve made regarding touch input related to text.</p>

<p>One of the biggest hurdles with UiTextInput is that you don&#8217;t get the benefit of the great UI work that Apple has put in their core iPhone text inputs. There&#8217;s no text selection, magnification loops, copy/paste or any of those other things we take for granted when we use the default inputs. If you want advanced editing features you have to implement them all yourself&#8212;and it&#8217;s a lot harder than it looks.</p>

<p>Text selection, for example, is something that you&#8217;re probably familiar with if you&#8217;ve used an iPhone or iPad but have you ever stopped to actually look what&#8217;s going on? The subtleties of the touch interaction are very intuitive but may not be what you expect when you think about it. For example, here are few things you may not have noticed when editing text in something like the default notepad.</p>

<ul>
<li><p>When you quickly single tap, the carat is placed in the text where you tapped but it&#8217;s position is based on word boundaries. A mouse click in a word processor places the carat at the point where you clicked but a tap in iPhone OS places it in front of or after the word, depending on which end of the word was nearest the tap.</p></li>
<li><p>Holding on a word will reveal a magnifying loop that gives you fine grained control over the selection. This is the <em>only</em> way you can place the carat within a word.</p></li>
<li><p>The select/select all/paste menu will appear if you long-tap. As a result it will always appear after the loop is shown but could also appear if you touch and release just before the loop shows (of course you&#8217;ll be selecting and pasting on a word boundary in the latter case).</p></li>
<li><p>The &#8220;select&#8221; option in the menu always starts by selecting a full word. Which word depends on where the carat is placed. If the carat is in a word then that word will be selected. If the carat is at the beginning of a word, between the space and the first letter, then the word following the carat is selected. If the carat is at the end of a word, before the following space, then the word preceding the carat is selected.</p></li>
<li><p>Double tapping a word will immediately select it. If you hold and drag on the second tap you can select a larger range based on where you drag. Interestingly, the range selection also has a magnifying loop&#8212;but with a different shape&#8212;so you can have fine grained control at the end of the selection.</p></li>
</ul>

<p>These are just a few of the subtle interactions that most iPhone users just do without thinking about.  If you&#8217;re going to implement your own UITextInput be sure to closely look at the existing text inputs and how you typically interact with them as you&#8217;ll need to implement yours the way users will expect it to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/04/30/dissecting-iphone-os-touch-actions-for-text/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>&#9734; Static Libraries with XCode and iPhone SDK</title>
		<link>http://jeffreysambells.com/posts/2010/04/16/static-libraries-with-xcode-and-iphone-sdk/</link>
		<comments>http://jeffreysambells.com/posts/2010/04/16/static-libraries-with-xcode-and-iphone-sdk/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 21:30:09 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[static library]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=508</guid>
		<description><![CDATA[One of the easiest ways to overwhelm yourself when developing for iPhone OS is trying the all-in-one approach to code management. I&#8217;ve done it countless times and rooting through a maze of groups and files in a project can drive you insane. After frustration push me to the edge one too many times I finally [...]]]></description>
			<content:encoded><![CDATA[<p>One of the easiest ways to overwhelm yourself when developing for <a href="http://developer.apple.com/iphone">iPhone OS</a> is trying the all-in-one approach to code management. I&#8217;ve done it countless times and rooting through a maze of groups and files in a project can drive you insane. After frustration push me to the edge one too many times I finally snapped and sat down to figure out a better way.</p>

<p>When you have a large project, there&#8217;s often a lot of code that is very generic&#8212;an XML parser, network connection manager, location manager&#8212;that could be placed in their own shared libraries to use across different projects. This separation of code vastly increases the cleanliness of each individual project but also has other advantages including:</p>

<ul>
<li>Clear boundaries for business logic, api requirements, and unit testing.</li>
<li>Less overlap in a single project when multiple developers are working together.</li>
</ul>

<p>Moving the code to a library also removes it from the project with the &#8220;business logic&#8221;, allowing you to focus on the task at hand and prevent you from &#8220;tweaking&#8221; libraries just to accommodate the business logic of one particular project.</p>

<p>The iPhone SDK doesn&#8217;t support custom frameworks or dynamic libraries so you may not have thought it was possible but iPhone OS does does support <strong>static libraries</strong> and therefore allows you to write re-useable code&#8212;with a few caveats. This is how libraries such as <a href="http://www.flurry.com/">Flurry</a> or <a href="http://code.google.com/apis/analytics/docs/tracking/mobileAppsTracking.html">Google Mobile Analytics</a> work.</p>

<p>The only disadvantage is that if you include other frameworks or libraries in your library you still need to include them ALL in your final project. Adding <em>MapKit</em> to a static library means you also need to add MapKit directly to the main project (which is why you need to add the SQL lib with Google analytics).</p>

<p>Creating your own library requires a few steps but it boils down to:</p>

<ol>
<li>Create an XCode project to contain all the code for a specific library.</li>
<li>Create a static library target with the appropriate configuration.</li>
<li>Create a project that will use the library.</li>
<li>Import your static library project into your main project.</li>
<li>Link in the static library.</li>
</ol>

<p>To simplify steps one and two even further, I&#8217;ve created an <a href="http://jeffreysambells.com/iphone-os-static-library-template/">iPhone OS Static Library</a> Project template for XCode. Download it and feel free to suggest any changes you&#8217;d like to see.</p>

<p>Usage instructions and a quick &#8220;How To&#8221; are <a href="http://jeffreysambells.com/iphone-os-static-library-template/">available on the project page</a>.</p>

<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/04/16/static-libraries-with-xcode-and-iphone-sdk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

