<?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>NathanHJones.com &#187; development</title>
	<atom:link href="http://nathanhjones.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://nathanhjones.com</link>
	<description>just thinking outloud</description>
	<lastBuildDate>Fri, 11 Nov 2011 06:55:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A Single Sign-on Pattern for Enterprise iOS Applications</title>
		<link>http://nathanhjones.com/2011/11/11/a-single-sign-on-pattern-for-enterprise-ios-applications/</link>
		<comments>http://nathanhjones.com/2011/11/11/a-single-sign-on-pattern-for-enterprise-ios-applications/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 06:30:32 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iphone sdk]]></category>
		<category><![CDATA[mSSO]]></category>
		<category><![CDATA[single sign-on]]></category>
		<category><![CDATA[SSO]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=341</guid>
		<description><![CDATA[In conversations with clients, we continue to hear how important single sign-on is to their enterprise mobile application strategy. According to a study earlier this year by Kelton Research 250 IT Managers, 21% of respondents indicated that they plan to deploy 20, or more, enterprise applications to their organization this year. In order for enterprises [...]]]></description>
			<content:encoded><![CDATA[<p>
In conversations with clients, we continue to hear how important single sign-on is to their enterprise mobile application strategy.  According to a <a href="http://www.echannelline.com/usa/story.cfm?item=26463">study earlier this year by Kelton Research 250 IT Managers</a>, 21% of respondents indicated that they plan to deploy 20, or more, enterprise applications to their organization this year.
</p>
<p>
In order for enterprises to realize the productivity gains factored into the investment decisions for those applications, IT Managers must explore options for enabling single sign-on for their users. In this post, we&#8217;ll outline a mobile single sign-on (mSSO) pattern for enterprise iOS applications.
</p>
<h2>Assumptions</h2>
<ol>
<li>Your company has a centralized single sign-on service exposed on the network &#8211; LDAP, Novell Access Manager, etc. This approach will work with a number of identity management architectures, but you will need to tailor credential management accordingly. For this demo, our service calls are simulated with hardcoded tokens.</li>
<li>Your company has a standardized credential timeout period or a way of dynamically distributing that value to applications. For this demo, we&#8217;ll use a static 30 minute timeout period.</li>
<li>You are able to sign and distribute builds to a device. This is important because keychain activities do not function in the simulator.</li>
</ol>
<h2>Implementation</h2>
<h4>Approach</h4>
<p>
Our approach will consist of creating three applications &#8211; two mock business applications and one logout application. Each application may contain its own logout functionality, but a single logout application makes the user&#8217;s activity of killing a session intuitive.  In practice, the mSSO pattern would be implemented as a stand-alone library which could be easily dropped into each of your various enterprise applications.
</p>
<p>
The business applications retrieve a unique authentication token which is included with each service request.  This token will be stored in the device&#8217;s <a href="http://developer.apple.com/library/ios/#documentation/Security/Reference/keychainservices/Reference/reference.html">keychain</a>, which will be shared across our suite of applications.  We will also maintain an &#8216;expiration date&#8217; within the keychain so that subsequent requests from our various apps can (if required) preemptively prompt the user to authenticate.
</p>
<p>
Authentication for this demo may be simplistic, but <a href="http://blogs.captechconsulting.com/blog/jack-cox/managing-complex-mobile-transactions">existing patterns</a> cover implementing authentication in a service-based mobile application.  For example, the &#8216;store credentials&#8217; logic presented in this example would live somewhere in that pattern&#8217;s &#8220;authenticateOperation&#8221;.
</p>
<p>
One possible extension of the mSSO pattern is to confirm that your credentials have not expired before issuing a call to the service.  You would use the mSSO pattern to sign your network requests, but rely on the service and response handlers to inform you that credentials have expired.  Checking credential expiration prior to making a service call limits unnecessary network traffic.
</p>
<h4>Configuration</h4>
<p>
There are two key steps that must be completed in order for your applications to share keychain access.</p>
<ol>
<li>Each application included in your mSSO effort must share a Bundle Seed ID, which allows shared keychain access between our suite of applications. This is configured within the <a href="http://developer.apple.com/ios/manage/overview/index.action">iOS management portal</a>. We&#8217;ll configure our applications using the default &#8216;Team ID&#8217; selection.</li>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/11/app1.png"><img src="http://nathanhjones.com/wp-content/uploads/2011/11/app1-300x136.png" alt="" title="app1" width="300" height="136" class="aligncenter size-medium wp-image-354" /></a><br />
<a href="http://nathanhjones.com/wp-content/uploads/2011/11/end-result.png"><img src="http://nathanhjones.com/wp-content/uploads/2011/11/end-result-300x61.png" alt="" title="end-result" width="300" height="61" class="aligncenter size-medium wp-image-355" /></a></p>
<li>We also need to enable and add an entitlements file that specifies that this application should be able to access the shared keychain. <span style="font-weight:bold;">This step is done after the Xcode project has been created.</span></li>
<ul>
<li>Select your app target in Xcode and choose the &#8216;Summary&#8217; tab.</li>
<li>Choose &#8216;Enable Entitlements&#8217; at the bottom.</li>
<li>Set the Entitlements File name to &#8220;mSSO&#8221; and hit return. Select &#8216;Create&#8217; when prompted.</li>
<li>Unless needed for your application, remove iCloud configuration settings.</li>
<li>Add a keychain value titled &#8220;mSSO&#8221;, our Bundle Seed ID is prepended to this value for us.</li>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/11/app-target-entitlements.png"><img src="http://nathanhjones.com/wp-content/uploads/2011/11/app-target-entitlements-300x137.png" alt="" title="app-target-entitlements" width="300" height="137" class="aligncenter size-medium wp-image-360" /></a><br />
<a href="http://nathanhjones.com/wp-content/uploads/2011/11/mSSO-entitlements-file.png"><img src="http://nathanhjones.com/wp-content/uploads/2011/11/mSSO-entitlements-file-300x35.png" alt="" title="mSSO-entitlements-file" width="300" height="35" class="aligncenter size-medium wp-image-361" /></a>
</ul>
</ol>
<h4>Development</h4>
<p>
We&#8217;ll walk through how to create App1 in detail, and then let you work through App2 and the Logout application. Let&#8217;s start by opening Xcode and creating a single view application.  Before we get started, add the Security.framework and create your entitlement files as outlined above.  <a href="http://useyourloaf.com/blog/2010/3/29/simple-iphone-keychain-access.html" target="_blank">Here</a> is a good primer for interacting with the keychain.
</p>
<ol>
<li>Add the custom <code>mSSOUtils</code> and <code>DateUtils</code> classes as outlined below.  Make sure that you import accordingly.  Due to changes in iOS related to <a href="http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iOS5.html#//apple_ref/doc/uid/TP30915195-SW4">ARC</a> (developer account required), you will need to disable ARC for the <code>mSSOUtils</code> class.  You can do so by selecting your target in Xcode and viewing the <span style="font-weight:bold;">Build Phases</span> tab. Expand the <span style="font-weight:bold;">Compile Sources</span> section and double click the <code>mSSOUtils</code> class to add the <code>-fno-objc-arc</code> compiler flag.  You may need to clean and build.<br />
<span style="font-weight:bold;">mSSOUtils:</span></p>

<div class="wp_codebox"><table><tr id="p3418"><td class="code" id="p341code8"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#define kmSSOKeychainGroup @&quot;3Q4M6DQ9WM.mSSO&quot;</span>
<span style="color: #6e371a;">#define kAuthenticationServiceName @&quot;com.captechconsulting.msso&quot;</span>
<span style="color: #6e371a;">#define kCredentialToken @&quot;mSSOAuthenticationToken&quot;</span>
<span style="color: #6e371a;">#define kCredentialExpiration @&quot;mSSOCredentialsExpirationDate&quot;</span>
<span style="color: #6e371a;">#define kExpirationTimeout 60.0 * 30    // 30 minute timeout</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// *** PRIVATE METHODS DEF *** //</span>
<span style="color: #a61390;">@interface</span> mSSOUtils <span style="color: #002200;">&#40;</span>Private<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> keychainSearch<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> getValueForIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifer;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value forIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> deleteValueForIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> mSSOUtils<span style="color: #002200;">:</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> authenticateWithUsername<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>username andPassword<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>password <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// for testing purposes, each call to this method authenticates successfully</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// set the token - app specific - change this in your App2 implementation</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self setValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;TokenSetFromApp1&quot;</span> forIdentifier<span style="color: #002200;">:</span>kCredentialToken<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// token set, now set the credential expiration</span>
        <span style="color: #002200;">&#91;</span>self extendCredentials<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Unable to set token.&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> logout <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// destroy token AND expiration date</span>
    <span style="color: #002200;">&#91;</span>self deleteValueForIdentifier<span style="color: #002200;">:</span>kCredentialToken<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self deleteValueForIdentifier<span style="color: #002200;">:</span>kCredentialExpiration<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// credential management</span>
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> extendCredentials <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>newExpireDate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>DateUtils dateWithTimeout<span style="color: #002200;">:</span>kExpirationTimeout<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>newExpireString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>DateUtils stringFromDate<span style="color: #002200;">:</span>newExpireDate withFormat<span style="color: #002200;">:</span>kDateFormat<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">BOOL</span> success <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self setValue<span style="color: #002200;">:</span>newExpireString forIdentifier<span style="color: #002200;">:</span>kCredentialExpiration<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>success<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Unable to extend credentials.&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> credentialsExpired <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// if no token exists, call credentials expired</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self credentialToken<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>expirationDate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self credentialExpirationDate<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>expirationDate<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// check for expiration</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>DateUtils dateInPast<span style="color: #002200;">:</span>expirationDate<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// if there is no expiration date, default to 'expired'</span>
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #11740a; font-style: italic;">// sign the request with current credentials - we'll add the token as an HTTP header field</span>
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableURLRequest</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> signRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableURLRequest</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>token <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self credentialToken<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>token<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>request addValue<span style="color: #002200;">:</span>token forHTTPHeaderField<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;auth-token&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> request;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// methods to retrieve credential information</span>
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> credentialToken <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>token <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getValueForIdentifier<span style="color: #002200;">:</span>kCredentialToken<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> token;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> credentialExpirationDate <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>expirationDateString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getValueForIdentifier<span style="color: #002200;">:</span>kCredentialExpiration<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>expirationDateString<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// convert to date</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>DateUtils dateFromString<span style="color: #002200;">:</span>expirationDateString withFormat<span style="color: #002200;">:</span>kDateFormat<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> displayAuthenticateView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>vc <span style="color: #002200;">&#123;</span>
    authenticateViewController <span style="color: #002200;">*</span>authenticateView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>authenticateViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;authenticateViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    UINavigationController <span style="color: #002200;">*</span>nc <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UINavigationController alloc<span style="color: #002200;">&#93;</span> initWithRootViewController<span style="color: #002200;">:</span>authenticateView<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>vc presentModalViewController<span style="color: #002200;">:</span>nc animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark PRIVATE METHODS</span>
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> keychainSearch<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>keychainSearch <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>keychainSearch setObject<span style="color: #002200;">:</span>kmSSOKeychainGroup forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecAttrAccessGroup<span style="color: #002200;">&#93;</span>;   <span style="color: #11740a; font-style: italic;">// inform the search that we're using the shared keychain</span>
    <span style="color: #002200;">&#91;</span>keychainSearch setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecClassGenericPassword forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecClass<span style="color: #002200;">&#93;</span>;   <span style="color: #11740a; font-style: italic;">// set the type to generic password - other options are certification, internet password, etc</span>
&nbsp;
    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>encodedIdentifier <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>identifier dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>keychainSearch setObject<span style="color: #002200;">:</span>encodedIdentifier forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecAttrGeneric<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>keychainSearch setObject<span style="color: #002200;">:</span>encodedIdentifier forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecAttrAccount<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>keychainSearch setObject<span style="color: #002200;">:</span>kAuthenticationServiceName forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecAttrService<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> keychainSearch;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> getValueForIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>search <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self keychainSearch<span style="color: #002200;">:</span>identifier<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>search setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecMatchLimitOne forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecMatchLimit<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// limit it to the first result</span>
    <span style="color: #002200;">&#91;</span>search setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kCFBooleanTrue forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecReturnData<span style="color: #002200;">&#93;</span>;    <span style="color: #11740a; font-style: italic;">// return data vs a dictionary of attributes</span>
&nbsp;
    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>value <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    OSStatus status <span style="color: #002200;">=</span> SecItemCopyMatching<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span>search,
                                          <span style="color: #002200;">&#40;</span>CFTypeRef <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&amp;</span>value<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>status <span style="color: #002200;">==</span> noErr<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>value bytes<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>value forIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// check if value exists</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>existingValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getValueForIdentifier<span style="color: #002200;">:</span>identifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>existingValue<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>existingValue isEqualToString<span style="color: #002200;">:</span>value<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #11740a; font-style: italic;">// update value</span>
            <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>search <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self keychainSearch<span style="color: #002200;">:</span>identifier<span style="color: #002200;">&#93;</span>;
&nbsp;
            <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>valueData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>value dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
            <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>update <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span>valueData, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecValueData, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
            OSStatus status <span style="color: #002200;">=</span> SecItemUpdate<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span>search,
                                            <span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span>update<span style="color: #002200;">&#41;</span>;
&nbsp;
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>status <span style="color: #002200;">==</span> errSecSuccess<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
            <span style="color: #002200;">&#125;</span>
            <span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
        <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
&nbsp;
        <span style="color: #11740a; font-style: italic;">// create new entry</span>
        <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>add <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self keychainSearch<span style="color: #002200;">:</span>identifier<span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>valueData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>value dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>add setObject<span style="color: #002200;">:</span>valueData forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kSecValueData<span style="color: #002200;">&#93;</span>;
&nbsp;
        OSStatus status <span style="color: #002200;">=</span> SecItemAdd<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span>add,<span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span>;
&nbsp;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>status <span style="color: #002200;">==</span> errSecSuccess<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
        <span style="color: #002200;">&#125;</span>
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
&nbsp;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> deleteValueForIdentifier<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>identifier <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>search <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self keychainSearch<span style="color: #002200;">:</span>identifier<span style="color: #002200;">&#93;</span>;
    SecItemDelete<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span>search<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p><span style="font-weight:bold;">DateUtils:</span></p>

<div class="wp_codebox"><table><tr id="p3419"><td class="code" id="p341code9"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> dateFromString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #a61390;">string</span> withFormat<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>format <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>dateFormatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span>format<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>date <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dateFormatter dateFromString<span style="color: #002200;">:</span><span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> date;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> stringFromDate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date withFormat<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>format; <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>dateFormatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span>format<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>dateString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dateFormatter stringFromDate<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> dateString;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> dateWithTimeout<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSTimeInterval<span style="color: #002200;">&#41;</span>timeout <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>now <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>timeoutDate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>now dateByAddingTimeInterval<span style="color: #002200;">:</span>timeout<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">return</span> timeoutDate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> dateInPast<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>date compare<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSOrderedAscending<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Within the generated <code>ViewController</code>, add two <code>UILabel</code> outlets/properties &#8211; token and expiration date &#8211; and a &#8220;Logout&#8221; button.  You&#8217;ll need to add two custom methods: logout and a selector to handle the foreground notification we register to receive.

<div class="wp_codebox"><table><tr id="p34110"><td class="code" id="p341code10"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> logout<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>mSSOUtils logout<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>mSSOUtils displayAuthenticateView<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> enterForeground<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// reset labels as we've entered the foreground</span>
    self.token.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mSSOUtils credentialToken<span style="color: #002200;">&#93;</span>;
    self.expiration.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>DateUtils stringFromDate<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>mSSOUtils credentialExpirationDate<span style="color: #002200;">&#93;</span> withFormat<span style="color: #002200;">:</span>kDateFormat<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
<li>You should only need to update two view lifecycle methods within <code>ViewController</code> &#8211; <code>viewDidLoad</code> and <code>viewWillAppear</code>.  Within <code>viewDidLoad</code>, we register to receive a notification when the app is brought to the foreground that triggers our UI updates.  The additions to <code>viewWillAppear</code> simply update our labels if there is data in the keychain.

<div class="wp_codebox"><table><tr id="p34111"><td class="code" id="p341code11"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// register for enter foreground notification to update labels</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
                                             selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>enterForeground<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span>
                                                 name<span style="color: #002200;">:</span>UIApplicationWillEnterForegroundNotification
                                               object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewWillAppear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewWillAppear<span style="color: #002200;">:</span>animated<span style="color: #002200;">&#93;</span>;
&nbsp;
    self.token.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mSSOUtils credentialToken<span style="color: #002200;">&#93;</span>;
    self.expiration.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>DateUtils stringFromDate<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>mSSOUtils credentialExpirationDate<span style="color: #002200;">&#93;</span> withFormat<span style="color: #002200;">:</span>kDateFormat<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Add an <code>authenticateViewController</code> to your project. This will be displayed modally when the users credentials need to be re-challenged. This example simply has a login button, but this is where you would include typical login fields.

<div class="wp_codebox"><table><tr id="p34112"><td class="code" id="p341code12"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> authenticate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// if authentication is successful, dismiss the view</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mSSOUtils authenticateWithUsername<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;username&quot;</span> andPassword<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;hashedPassword&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>self dismissModalViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>   
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Last up, we&#8217;ll need to update our application delegate to confirm our credentials are valid when the app launches or is brought back from the background.  You&#8217;ll need to update the <code>didFinishLaunchingWithOptions</code> and <code>applicationWillEnterForeground</code> methods as noted below:

<div class="wp_codebox"><table><tr id="p34113"><td class="code" id="p341code13"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>application<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application didFinishLaunchingWithOptions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>launchOptions <span style="color: #002200;">&#123;</span>
    self.window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch.</span>
    self.viewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    self.window.rootViewController <span style="color: #002200;">=</span> self.viewController;
    <span style="color: #002200;">&#91;</span>self.window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// credentials don't exist or are expired - display the authenticate view</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mSSOUtils credentialsExpired<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>mSSOUtils displayAuthenticateView<span style="color: #002200;">:</span>self.viewController<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationWillEnterForeground<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// credentials don't exist or are expired - display the authenticate view</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mSSOUtils credentialsExpired<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>mSSOUtils displayAuthenticateView<span style="color: #002200;">:</span>self.viewController<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Now, rinse and repeat for App2.  You can follow the same steps for the Logout application, but you really just need a single view that calls <code>[mSSOUtils logout]</code> on launch and informs the user their credentials have been terminated.

<div class="wp_codebox"><table><tr id="p34114"><td class="code" id="p341code14"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>application<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application didFinishLaunchingWithOptions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>launchOptions <span style="color: #002200;">&#123;</span>
    self.window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch.</span>
    self.viewController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ViewController alloc<span style="color: #002200;">&#93;</span> initWithNibName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ViewController&quot;</span> bundle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    self.window.rootViewController <span style="color: #002200;">=</span> self.viewController;
    <span style="color: #002200;">&#91;</span>self.window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// logout to kill credentials</span>
    <span style="color: #002200;">&#91;</span>mSSOUtils logout<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>applicationWillEnterForeground<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>   
    <span style="color: #11740a; font-style: italic;">// logout to kill credentials</span>
    <span style="color: #002200;">&#91;</span>mSSOUtils logout<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</li>
</ol>
<p>
Here are a couple helpful hints while developing your solution:</p>
<ul>
<li>We&#8217;ve disabled ARC for the <code>mSSOUtils</code> class, which means you need to handle memory management yourself.</li>
<li>When building your application, if you get a Mach-O Linker error, ensure that you&#8217;ve added the Security.framework.</li>
</ul>
<h4>Testing</h4>
<p>
Our testing won&#8217;t get too crazy, but at this point you should be all set to install our suite of apps on your device.
</p>
<p>
We&#8217;ll start by opening App1 and simulating an authentication call. Once the modal view is dismissed, our token and expiration date should be updated &#8211; expiration being now + 30 minutes.  From here, jump to App2 where you should see the App1 token/expiration. Logout and re-authenticate within App2, which will update our token and expiration date.  Now, we&#8217;ll wait 30 minutes and test whether our token expires. After 30 minutes, open App1, you should be prompted with an authentication view.  Authenticate and then open the Logout app.  Enter App2 from the multi-task tray, you should be prompted to authenticate once again.
</p>
<p>
The test sequence above has been captured in the screenshots below.  Note: for brevity, I&#8217;ve excluded screenshots of each authentication view except for the final step.<br />
<a href="http://nathanhjones.com/wp-content/uploads/2011/11/mSSO-Testing.jpg"><img src="http://nathanhjones.com/wp-content/uploads/2011/11/mSSO-Testing-300x143.jpg" alt="" title="mSSO Testing" width="300" height="143" class="aligncenter size-medium wp-image-374" /></a>
</p>
<h4>Closing</h4>
<p>
This post presents a pattern for implementing single sign-on for your enterprise iOS applications. It should give you the foundation needed to begin implementing single sign-on in your applications. I&#8217;ve attached the source for App1. If you&#8217;ve got questions or are interested in additional source files, I&#8217;m <a href="http://twitter.com/nathanhjones">@nathanhjones</a> on Twitter.
</p>
<div style="border: 1px solid #cdcdcd; background-color: #ffffff; padding: 10px 0 10px 10px;">
<span style="font-weight:bold;">Project files:</span> <a href="http://nathanhjones.com/wp-content/uploads/2011/11/mssoapp1.zip">mssoapp1.zip</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2011/11/11/a-single-sign-on-pattern-for-enterprise-ios-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with JSON in iOS5</title>
		<link>http://nathanhjones.com/2011/11/03/getting-started-with-json-in-ios/</link>
		<comments>http://nathanhjones.com/2011/11/03/getting-started-with-json-in-ios/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 03:30:20 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[ios5]]></category>
		<category><![CDATA[iphone sdk]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=315</guid>
		<description><![CDATA[Update: This post has been cross-posted on my employers blog. JSON has taken the data-interchange world by storm with its&#8217; lightweight, easy to understand format. The explosion of mobile apps, and their consumption of network based data, helped fuel JSON&#8217;s growth. CapTech&#8217;s (my employer) recommended approach for web services utilizes JSON as the interchange format. [...]]]></description>
			<content:encoded><![CDATA[<p>
<span style="font-weight:bold">Update:</span> This post has been cross-posted on my employers <a href="http://blogs.captechconsulting.com/blog/nathan-jones/getting-started-json-ios5">blog</a>.
</p>
<p><a href="http://www.json.org/">JSON</a> has taken the data-interchange world by storm with its&#8217; lightweight, easy to understand format. The explosion of mobile apps, and their consumption of network based data, helped fuel JSON&#8217;s growth. <a href="http://blogs.captechconsulting.com/blog/jack-cox/soap-vs-rest-mobile-services" target="_blank">CapTech&#8217;s (my employer) recommended approach for web services</a> utilizes JSON as the interchange format.</p>
<p>While JSON has been around for several years &#8211; <a href="http://tools.ietf.org/html/rfc4627" target="_blank">RFC4627</a> was published in July of 2006 &#8211; working with JSON in an iOS project required that you download one of the many frameworks and integrate it into your project. My personal choice has been SBJSON &#8211; <a href="https://github.com/stig/json-framework">https://github.com/stig/json-framework</a>.</p>
<p>However, with the release of iOS5, Apple has finally included native support for reading and writing JSON with the class <a href="http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html" target="_blank"><span style="font-weight: bold;">NSJSONSerialization</span></a>.</p>
<p>Why might you consider using the native JSON API? First and foremost, Apple delivered, Apple supported. While support for most third-party libraries is good, you can&#8217;t beat updated, built-in, backwards compatible support (for future versions of the OS) on day one of a new SDK.</p>
<p>One unfortunate con, use of NSJSONSerialization is limited to devices running iOS5. While iOS5 adoption is moving at a great pace, this still vastly limits your install base. In the case of some enterprises with field devices deployed with previous versions of the OS, this may not be an option for quite some time.</p>
<p>It&#8217;s important to note, calling any of the NSJSONSerialization methods on a device running an older version of iOS will not cause the application to crash. It simply won&#8217;t work and will continue on as if the call was never made. Obviously, there are other impacts of this, but this may fit some needs.</p>
<p>Now, let&#8217;s cover implementing the 4 read/write methods that Apple has exposed. As you can see below, using NSJSONSerialization in your projects is incredibly easy, typically requiring just a few lines of code. NSJSONSerialization supports the reading and writing of JSON data via static data or an instance of NS*Stream. The NS*Stream examples below are rudimentary, but they convey what is needed in order for NSJSONSerialization to do its&#8217; job.</p>
<h3>Parsing JSON Data</h3>
<div>
<p>The parsing methods accept an options parameter which allow you to pass different instructions to manipulate what type of foundation object you get back.</p>
<ul>
<li>NSJSONReadingAllowFragments: instructs the parser to allow top-level objects that are neither an NSArray nor NSDictionary</li>
<li>NSJSONReadingMutableContainers: instructs the parser to generate NSMutableArray and NSMutableDictionary objects</li>
<li>NSJSONReadingMutableLeaves: instructs the parser to generate NSMutableString objects</li>
</ul>
</div>
<div>
<h4>Method: JSONObjectWithData</h4>
<p>This method allows us to create a JSON object from an instance of NSData.  In this example, we&#8217;ll assume that an authentication request was successful (see below).  The first portion of the code will be to generate the mock-JSON response we received from the service.  The code will parse that response and create a foundation object.  From there, we&#8217;ll check if the object is an NSDictionary (there are a couple ways of doing this) and, if so, log the returned message and my token.</p>

<div class="wp_codebox"><table><tr id="p31519"><td class="code" id="p315code19"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>data <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Authentication Successful&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;auth_response&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;abc123&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;auth_token&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>writeError <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>jsonData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization dataWithJSONObject<span style="color: #002200;">:</span>data options<span style="color: #002200;">:</span>NSJSONWritingPrettyPrinted error<span style="color: #002200;">:&amp;</span>amp;writeError<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// parse the JSON data into what is ultimately an NSDictionary</span>
    <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>parseError <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #a61390;">id</span> jsonObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization JSONObjectWithData<span style="color: #002200;">:</span>jsonData options<span style="color: #002200;">:</span>NSJSONReadingAllowFragments error<span style="color: #002200;">:&amp;</span>amp;parseError<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// test that the object we parsed is a dictionary - perhaps you would test for something different</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>jsonObject respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>objectForKey<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Response: %@&quot;</span>, <span style="color: #002200;">&#91;</span>jsonObject objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;auth_response&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Token: %@&quot;</span>, <span style="color: #002200;">&#91;</span>jsonObject objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;auth_token&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h4>Method: JSONObjectWithStream</h4>
<p>This method allows us to create a JSON object from an input stream. When and why to use NSInputStream is out of scope for this post. However, if you have a large chunk of JSON data you want to parse, it may be one option to explore.</p>
<p>In this example, we create an instance of NSData that contains JSON formatted tweet information. While not the recommended network communication approach, this allows us to quickly generate an NSData object for our stream.  Once the stream is up, we&#8217;ll create a foundation object from the JSON data, test that it is an NSDictionary (which we expect given the source data we&#8217;re retrieving), and then log the tweet to the console.</p>
<p>It&#8217;s important to note that an <strong>NS*Stream must be created AND configured in order for NSJSONSerialization to work properly</strong>. Once parsed, we simply log each of the tweets to the console.</p>

<div class="wp_codebox"><table><tr id="p31520"><td class="code" id="p315code20"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>tweets <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.search.twitter.com/search.json?q=from:nathanhjones&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSInputStream</span> <span style="color: #002200;">*</span>twitterStream <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSInputStream</span> alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>tweets<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>twitterStream open<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>twitterStream<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>parseError <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
        <span style="color: #a61390;">id</span> jsonObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization JSONObjectWithStream<span style="color: #002200;">:</span>twitterStream options<span style="color: #002200;">:</span>NSJSONReadingAllowFragments error<span style="color: #002200;">:&amp;</span>amp;parseError<span style="color: #002200;">&#93;</span>;        
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>jsonObject respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>objectForKey<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>tweet <span style="color: #a61390;">in</span> <span style="color: #002200;">&#91;</span>jsonObject objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;results&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Tweet: %@&quot;</span>, <span style="color: #002200;">&#91;</span>tweet objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;text&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
            <span style="color: #002200;">&#125;</span>
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed to open stream.&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

</div>
<h3>Writing JSON Data</h3>
<div>The JSON writing methods also have an options parameter, but it&#8217;s currently limited to a single option.</p>
<ul>
<li>NSJSONWritingPrettyPrinted: instructs the writer to generate JSON with whitespace designed to make output more readable. If this option is not used, the most compact JSON possible will be generated.</li>
</ul>
<h4>Method: dataWithJSONObject</h4>
<p>This method allows us to create a JSON formatted NSData object from a foundation object &#8211; typically NSDictionary or NSArray.</p>
<p>In this example, we&#8217;ll build a dictionary of authentication credentials and then convert that to JSON as if we were posting it to an authentication service.</p>

<div class="wp_codebox"><table><tr id="p31521"><td class="code" id="p315code21"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>data <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test@test.com&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;user&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;mypass&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;pass&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>jsonData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization dataWithJSONObject<span style="color: #002200;">:</span>data options<span style="color: #002200;">:</span>NSJSONWritingPrettyPrinted error<span style="color: #002200;">:&amp;</span>amp;writeError<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>jsonString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>jsonData encoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;JSON Output: %@&quot;</span>, jsonString<span style="color: #002200;">&#41;</span>;</pre></td></tr></table></div>

<h4>Method: writeJSONObject:toStream</h4>
<p>This method allows us to write our JSON directly to an output steam. Again, when to use NSOutputStream is out of scope for this post, but it is an option. For this example, we&#8217;ll build an array of all tweet details for my last 3 tweets. We&#8217;ll then scrub that data down to 3 key pieces of information for each tweet, which we will then write to an output stream. In this case, we&#8217;ll simply write the contents to a local file.</p>

<div class="wp_codebox"><table><tr id="p31522"><td class="code" id="p315code22"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// get tweet data and convert to foundation object</span>
    <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>tweetData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.search.twitter.com/search.json?q=from:nathanhjones&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>parseError <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #a61390;">id</span> jsonObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization JSONObjectWithData<span style="color: #002200;">:</span>tweetData options<span style="color: #002200;">:</span>NSJSONReadingAllowFragments error<span style="color: #002200;">:&amp;</span>amp;parseError<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// initialize an array to hold our reformatted tweets</span>
    <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>tweets <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// check that we received a dictionary - there are 'header' objects sent by twitter</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>jsonObject respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>objectForKey<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">// loop through all the actual tweets</span>
        <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>tweet <span style="color: #a61390;">in</span> <span style="color: #002200;">&#91;</span>jsonObject objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;results&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>   
            <span style="color: #11740a; font-style: italic;">// create a dictionary of minimal tweet data and add to output</span>
            <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>scrubbedTweet <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span>
                                           <span style="color: #002200;">&#91;</span>tweet objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;id&quot;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;id&quot;</span>,
                                           <span style="color: #002200;">&#91;</span>tweet objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;created_at&quot;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;created_at&quot;</span>,
                                           <span style="color: #002200;">&#91;</span>tweet objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;text&quot;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;text&quot;</span>,
                                           <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
            <span style="color: #002200;">&#91;</span>tweets addObject<span style="color: #002200;">:</span>scrubbedTweet<span style="color: #002200;">&#93;</span>;        
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// initialize and open the stream</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>documents <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>path <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@/tweets.json&quot;</span>, documents<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSOutputStream</span> <span style="color: #002200;">*</span>stream <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSOutputStream</span> alloc<span style="color: #002200;">&#93;</span> initToFileAtPath<span style="color: #002200;">:</span>path append<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>stream open<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// write JSON representation of our tweet array to file</span>
    <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>writeError <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    NSInteger bytesWritten <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSJSONSerialization writeJSONObject<span style="color: #002200;">:</span>tweets toStream<span style="color: #002200;">:</span>stream options<span style="color: #002200;">:</span>NSJSONWritingPrettyPrinted error<span style="color: #002200;">:&amp;</span>amp;writeError<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>bytesWritten &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error writing JSON Data&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>One additional method I find particularly interesting, <strong>isValidJSONObject</strong>.  An easy way to validate that the object you’ve created can be converted to JSON data.  I could be wrong, but I don’t recall any of the third-party libraries I’ve used having such a method.</p>
<p>If you’ve got questions, I’m @nathanhjones.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2011/11/03/getting-started-with-json-in-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Reusable UIViews with a Drop Shadow [Tutorial]</title>
		<link>http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/</link>
		<comments>http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 02:57:33 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Drop Shadow]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=282</guid>
		<description><![CDATA[Update: I&#8217;ve updated the post to reflect what code requires iOS 4.0 and later.  Basically, the layer properties for the drop shadow. I&#8217;m working on an internal iPhone application for my employer.  It&#8217;s data-centric, as I&#8217;m sure most enterprise grade apps are, and as such consists mostly of UITableViews so users can view and drill [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> I&#8217;ve updated the post to reflect what code requires iOS 4.0 and later.  Basically, the layer properties for the drop shadow.</p>
<p>I&#8217;m working on an internal iPhone application for my employer.  It&#8217;s data-centric, as I&#8217;m sure most enterprise grade apps are, and as such consists mostly of UITableViews so users can view and drill into each subsequent level of detail.</p>
<p>One requirement was to have summary data points from previous screens on each view.  Nothing mind blowing that a tableHeaderView couldn&#8217;t solve.  However, a couple of these summary views would be reused and had several data points.  To complicate things, I needed a drop shadow to distinguish the header from the table (they are the same color in this particular case).</p>
<p>I decided to subclass UIView and do the layout in IB.  This kept the code clean and was a BREEZE to lay out (and change layouts as we&#8217;ve now done several times).  Unfortunately, it wasn&#8217;t as straight-forward as I originally thought.  However, with a little help from <a href="http://www.raywenderlich.com/" target="_blank">Ray Wenderlich</a>, I was able to get it implemented.  This is a quick tutorial for those out there that may be struggling with something similar.  <strong><em>The technique outlined below is only available for apps targeting iOS devices running at least 4.0.</em></strong></p>
<h3>Create the project</h3>
<p>To get started, create a view based application &#8211; I named mine <strong>ReusableTableHeaders</strong>.  Within <strong>ReusableTableHeadersViewController.h</strong>, change the parent class from UIViewController to UITableViewController and define two instance variables &#8211; <strong>tblData</strong> (UITableView) and <strong>data</strong> (NSArray).  <strong>tblData</strong> will be our table view (so remember to add IBOutlet) and <strong>data</strong> will be a simple array of information to display.  Before leaving R<strong>eusableTableHeadersViewController.h</strong>, add UITableViewDelegate and UITableViewDataSource to the interface definition.</p>
<p>Pop over to the implementation file.  The first thing I always do is synthesize and update dealloc accordingly.  This tends to save me from myself later.  Within the <strong>viewDidLoad</strong> method, fill <strong>data</strong> with some values.  I went with the oh-so-clever &#8216;Value 1&#8242;, &#8216;Value 2&#8242;, and &#8216;Value 3&#8242;.  Once complete, open up IB and we&#8217;ll set the table view up before we build and run to make sure we&#8217;re ok.</p>
<p>Within IB, delete the UIView that&#8217;s currently there and replace it with a UITableView.  Connect that to both <strong>tblData</strong> and <strong>view</strong> within the File Owner.  You&#8217;ll also want to set the File Owner as the data source and delegate.  I changed my table view style to grouped and added a background.  That&#8217;s totally your call.</p>
<p>Here&#8217;s a quick shot of what IB looks like:</p>
<p style="text-align: center;"><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-2.37.33-PM.png"><img class="aligncenter size-full wp-image-285" title="IB Connections" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-2.37.33-PM.png" alt="" width="298" height="208" /></a></p>
<p>Build and Run to make sure we&#8217;re on the same page thus far.  Here&#8217;s a quick shot of what I get.</p>
<p style="text-align: center;"><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-2.36.52-PM.png"><img class="aligncenter size-full wp-image-286" title="Build and Run - Progress so far" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-2.36.52-PM.png" alt="" width="274" height="470" /></a></p>
<h3>Subclassing UIView</h3>
<p>Now that we have the foundation in place, let&#8217;s get started on the header view.  Add a new Objective-C class to your project.  When prompted to choose your type, you&#8217;ll also want to set the subclass option to UIView.  I named my class <strong>HeaderView</strong>. We&#8217;re going to go ahead and add a nib as well.  Add a new view based nib to your project &#8211; I named mine <strong>HeaderView.xib</strong>.</p>
<p>Once your class files and nib are created, define a UILabel instance variable within the .h (mine is titled <strong>lblTitle</strong>) and set it as an outlet.  Now, hop over to the implementation file, synthesize, and update the dealloc method.  Also, be sure to include <strong>&lt;QuartzCore/QuartzCore.h&gt;</strong>.  Within the <strong>initWithFrame</strong> method, add the following code:</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.43.55-PM.png"><img class="aligncenter size-full wp-image-295" title="initWithFrame" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.43.55-PM.png" alt="" width="484" height="248" /></a></p>
<p>The code is pretty straight-forward.  The first block loads the HeaderView nib file and sets this itself equal to the loaded nib.  The second block of code handles setting the drop shadow (<strong>note: the <em>layer.shadow*</em> related code only works in iOS 4.0 and above</strong>).  Manipulating the shadow color can produce some pretty cool effects but we&#8217;ll stick with the generic black for now.  With that done, it&#8217;s time to set our nib up in IB.</p>
<h3>Setting up the view in IB</h3>
<p>Unfortunately, and I&#8217;m not sure why, you can&#8217;t alter the height of the default view when creating a view based nib.  My solution, delete the existing view and add a new one.  Set your desired dimensions &#8211; for this tutorial we go with 320 by 60.  You&#8217;ll also want to drag another UIView and UILabel into the nib as subviews.  I actually added two UILabels &#8211; a &#8216;title&#8217; label and the label I&#8217;ll update programmatically.</p>
<p>Select the top level view and open Inspector.  Set the class to your custom class &#8211; <strong>HeaderView</strong>.  While in the Inspector, set the background color clear.</p>
<p>Now select the UIView subview and change the height dimension to just slightly less than our &#8216;parent&#8217; view.  For this tutorial, I went with a difference of 5 points &#8211; 320 by 55 &#8211; and then aligned the two UIViews at the top.  Change the background color to whatever you&#8217;d like your header to be.</p>
<p>Link up one of the UILabel&#8217;s to <strong>lblTitle</strong> you defined in <strong>HeaderView.h</strong> and you should be all set.</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-9.33.58-PM.png"><img class="aligncenter size-full wp-image-306" title="IB Setup" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-9.33.58-PM.png" alt="" width="432" height="474" /></a></p>
<h3>Using the view</h3>
<p>First things first, import your custom class within <strong>ReusableTableHeadersViewController</strong>.  From here, you have several options about where to implement your custom view.  The requirement I needed to satisfy required that I use the viewWillAppear method as information could be updated as views pushed and popped.  I wanted to ensure I had the most up-to-date information presented.  For this tutorial, we&#8217;ll load it within viewDidLoad.</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.53.14-PM.png"><img class="aligncenter size-full wp-image-297" title="Using our custom view" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.53.14-PM.png" alt="" width="503" height="213" /></a></p>
<p>Walking through what we just did; we instantiate the view, set the title label, and then load it into our table view as the header.</p>
<h3>Wrapping Up</h3>
<p>And we&#8217;re done! Build and run and you should have something that resembles the screenshot below!</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.55.40-PM.png"><img class="aligncenter size-full wp-image-299" title="End result" src="http://nathanhjones.com/wp-content/uploads/2011/02/Screen-shot-2011-02-20-at-8.55.40-PM.png" alt="" width="426" height="331" /></a></p>
<p>Here&#8217;s the project files: <a href="http://nathanhjones.com/wp-content/uploads/2011/02/ReusableTableHeaders.zip" target="_blank">ReusableTableHeaders.zip</a>.</p>
<p>Well, that&#8217;s my first iOS tutorial.  Hope it helps and be sure to let me know what works and what doesn&#8217;t work in the comments.  I hope to have several more over the course of the year.</p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Google AdWords gets partial HTML5 makeover</title>
		<link>http://nathanhjones.com/2010/09/15/google-adwords-gets-partial-html5-makeover/</link>
		<comments>http://nathanhjones.com/2010/09/15/google-adwords-gets-partial-html5-makeover/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 03:48:55 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[adwords]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[local storage]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=279</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve posted but I saw something this evening that I thought was worth posting.  I&#8217;ve been spending a lot of my free time lately developing and promoting an iPhone app.  I&#8217;ve got a second in process so this whole process has been a great learning experience.  Part of my mobile [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve posted but I saw something this evening that I thought was worth posting.  I&#8217;ve been spending a lot of my free time lately developing and promoting an <a href="http://apptory.com" target="_self">iPhone app</a>.  I&#8217;ve got a second in process so this whole process has been a great learning experience.  Part of my mobile obsession extends to browser based apps (i.e. not App Store downloads) that utilize some of the advancements in the <a href="http://dev.w3.org/html5/spec/Overview.html">HTML5 specification </a>(I use the word &#8216;specification&#8217; loosely as I&#8217;ll include local storage, geolocation, etc under the same umbrella on this site).</p>
<p>HTML5 has it&#8217;s pro&#8217;s and con&#8217;s that each developer needs to weigh (we won&#8217;t get into that here) but <a href="http://dev.w3.org/html5/webstorage/">web storage</a> and <a href="http://dev.w3.org/html5/webdatabase/">web database</a> are great advances.  The packaged modern mobile browsers (Safari, Android browser, etc) all support the specification which allows applications to store information from within their application that persists from session to session.  It can be very powerful&#8230;but it is definitely open for exploitation.  A common example is Gmail which utilizes the storage feature (along with App Cache) to allow you to work within the Gmail web-app while you are not connected to a network.  It also speeds up the entire user experience.</p>
<p>All that being said, I logged into AdWords this evening to begin preparing my campaign for this weekend and noticed they&#8217;ve begun utilizing local storage.  The great thing about it is that they request your approval rather than doing it behind the scenes.  Given that any website can create a &#8216;database&#8217; on your local machine for storing information, I think that all user-agents (think Safari, Firefox, Chrome, etc) should force the user to authorize each use of local storage &#8211; i.e. one approval for gmail.com).</p>
<p>In short, it&#8217;s really cool that more and more sites are beginning to implement these features as browsers roll-out support but I&#8217;m more impressed that AdWords asks for permission.  I think more web-apps should follow the AdWords lead!</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2010/09/Screen-shot-2010-09-15-at-11.28.09-PM.png"><img class="aligncenter size-full wp-image-280" title="AdWords Implements HTML5 database feature" src="http://nathanhjones.com/wp-content/uploads/2010/09/Screen-shot-2010-09-15-at-11.28.09-PM.png" alt="" width="521" height="212" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2010/09/15/google-adwords-gets-partial-html5-makeover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gone Mobile with WPtouch</title>
		<link>http://nathanhjones.com/2010/01/14/gone-mobile-with-wptouch/</link>
		<comments>http://nathanhjones.com/2010/01/14/gone-mobile-with-wptouch/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 04:06:45 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[nathanhjones.com]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wptouch]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=259</guid>
		<description><![CDATA[The other day I read Justin Levy&#8217;s post on going mobile with WPtouch and just had to experiment.  I haven&#8217;t previously had a mobile specific version so it&#8217;s definitely an exciting move. Here&#8217;s a quick round up of my experience. Installation Installation was a breeze.  WPtouch is a WordPress plugin, all it took was downloading the files, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I read <a href="http://justinrlevy.com/2010/01/05/gone-mobile/">Justin Levy&#8217;s post on going mobile</a> with <a href="http://www.bravenewcode.com/wptouch/">WPtouch</a> and just had to experiment.  I haven&#8217;t previously had a mobile specific version so it&#8217;s definitely an exciting move. Here&#8217;s a quick round up of my experience.</p>
<h3>Installation</h3>
<p>Installation was a breeze.  WPtouch is a WordPress plugin, all it took was downloading the files, uploading it to my server and activating it from the dashboard.  Once activated we were up-and-running with the vanilla install.  Now on to customizing&#8230;</p>
<h3>Setup</h3>
<p>WPtouch offers a wide array of customizing (sorry, this is a word I&#8217;ve gotten way too used to in the SAP world) options from enabling AJAX comment posting to custom CSS/Javascript inclusion.  I kept my install fairly simple but there were a couple things I changed.</p>
<ol>
<li>I call myself a developer so I went with a snazzy App Store icon as my mobile banner image (see end of the post). WPtouch has a pretty good selection of images although they&#8217;re mostly centered around the iPhone.  If nothing meets your needs you&#8217;re more than welcome to upload a custom file.<a href="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-banner-icons.png"><img title="WPtouch-banner-icons" src="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-banner-icons.png" alt="" width="508" height="290" /></a></li>
<li>Linking of my AdSense and Analytics accounts.  Must haves&#8230;AdSense to collect those occasional pennys and Analytics to obviously to continue to understand how people flow through the site.  Adding both was EXTREMELY easy to do with a custom section for each.<a href="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-adsense-and-analytics.png"><img title="WPtouch-adsense-and-analytics" src="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-adsense-and-analytics.png" alt="" width="542" height="149" /></a></li>
</ol>
<p>WPtouch gives you the option to display a &#8216;desktop&#8217; (i.e. non-mobile) version of your website to users on their first visit and include the ability to toggle mobile vs. desktop in your theme footer.  I get the potential draw but if you&#8217;re going to go mobile, I&#8217;m not sure why you wouldn&#8217;t always default mobile and allow them to switch back if they want.</p>
<p>Anyways, you can also change what icon is used for each post and how much information about the post is shown (e.g. just the title, title and a teaser, tags, categories, etc).  I played with the settings a bit but I think that&#8217;s really more of a personal choice&#8230;at least until I get time to test and study analytic data.</p>
<h3>Additions and Suggestions</h3>
<p>For a donation supported plugin I can&#8217;t really complain.  It&#8217;s easy and relatively robust but there are still a couple things I would like to see enhanced:</p>
<ol>
<li>I understand it&#8217;s a mobile device and landscape is limited but a second &#8216;title&#8217; (under NathanHJones.com below) would be ideal.  Obviously, each blog owner would need to be smart about how it was used.</li>
<li>Better AdSense rendering.  This may be slightly out of the WPtouch developers hands but I noticed that AdSense ads show up very boxy compared to the smooth WPtouch design.  I don&#8217;t know if that&#8217;s anything they can fix or perhaps me just being new to AdSense mobile but it didn&#8217;t exactly flow together.</li>
</ol>
<p><a href="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-adsense-rendering.jpg"><img title="WPtouch-adsense-rendering" src="http://nathanhjones.com/wp-content/uploads/2010/01/WPtouch-adsense-rendering.jpg" alt="" width="230" height="133" /></a></p>
<p>If you&#8217;re mobile version is powered by WPtouch leave a comment and let me know what you think!  Finally, here&#8217;s a fullscreen shot of NathanHJones.com&#8230;the mobile version&#8230;from my iPhone.</p>
<p><a href="http://nathanhjones.com/wp-content/uploads/2010/01/nathanhjones.com-mobile.jpg"><img title="nathanhjones.com-mobile" src="http://nathanhjones.com/wp-content/uploads/2010/01/nathanhjones.com-mobile.jpg" alt="" width="224" height="336" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2010/01/14/gone-mobile-with-wptouch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Resolutions for 2010</title>
		<link>http://nathanhjones.com/2010/01/03/my-resolutions-for-2010/</link>
		<comments>http://nathanhjones.com/2010/01/03/my-resolutions-for-2010/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 23:35:10 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[communication]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[resolutions]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=245</guid>
		<description><![CDATA[I&#8217;ve been kicking around the idea of publishing my personal resolutions for 2010 for a couple weeks and just decided to pull the trigger.  My thoughts, what better way of pushing myself to follow through than to publish them on the web for all to see.  I&#8217;ll try to take a couple checkpoints throughout the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been kicking around the idea of publishing my personal resolutions for 2010 for a couple weeks and just decided to pull the trigger.  My thoughts, what better way of pushing myself to follow through than to publish them on the web for all to see.  I&#8217;ll try to take a couple checkpoints throughout the year to let you know how I&#8217;m progressing.</p>
<p>So, without further ado, here are my resolutions for 2010:</p>
<ol>
<li>Develop and iPhone app.  I have a few ideas but I won&#8217;t reveal those just yet.  Look out for the announcement when the app is ready though <img src='http://nathanhjones.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Blog more &#8211; 3-4 times per month is my target.  I plan on blogging about my iPhone development experience as well as about some topics I&#8217;ve been hoarding from my day job on implementing SAP SRM 7.0.</li>
<li>Clean up my resume and create a web-ready version (linked on this blog obviously).</li>
<li>Develop a new website &#8211; I suspect this will likely be to complement the iPhone app but I would like to build a custom WordPress theme for <a href="http://nathanhjones.com">nathanhjones.com</a>.</li>
<li>Reach 500 followers and 1,500 tweets on <a href="http://twitter.com/nathanhjones" target="_blank">Twitter</a>.  I hover between 140 and 150 followers and just hit 600 tweets today.</li>
<li>Exercise more &#8211; 4-5 times per week.  Throughout the last couple years I have been working out 2-4 times a week but I would like to raise the bar a bit at 4 to 5 times to help get in better shape and shed a few pounds.</li>
<li>Lower my golf score.  Notice I didn&#8217;t say handicap there <img src='http://nathanhjones.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  Over the last few years I&#8217;ve only been able to play a couple times a year because work has consumed so much of my time.  My goal for 2010 is to play more and get my average score consistently in the 90&#8242;s (high 90&#8242;s is ok by me for this year).</li>
</ol>
<p>I wanted to list 10 (for some reason that sounded like such a nice, even number) but this is all I could muster today.  If I manage to achieve all of this with time to spare in 2010 (unlikely, unless you find me a new job)&#8230;I&#8217;ll add a couple more.</p>
<p>By the way, how does everyone feel about the fact that years will now almost always be prefaced with &#8216;twenty&#8217; instead of &#8216;two-thousand&#8217;?!?</p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2010/01/03/my-resolutions-for-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazon Brings Enterprise Databases to the Cloud</title>
		<link>http://nathanhjones.com/2008/10/05/amazon-brings-enterprise-databases-to-the-cloud/</link>
		<comments>http://nathanhjones.com/2008/10/05/amazon-brings-enterprise-databases-to-the-cloud/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 02:28:56 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[amazon web service]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=97</guid>
		<description><![CDATA[The people over at Amazon Web Services have been busy at work the last couple weeks. The Elastic Compute Cloud (EC2) team has rolled out two significant computing options over that will really help pave the way for more enterprise adoption of their services. Last Tuesday, Amazon announced that it plans to unveil the ability [...]]]></description>
			<content:encoded><![CDATA[<p>The people over at Amazon Web Services have been busy at work the last couple weeks.  The Elastic Compute Cloud (EC2) team has rolled out two significant computing options over that will really help pave the way for more enterprise adoption of their services.</p>
<p>Last Tuesday, Amazon announced that it plans to unveil the ability to <a href="http://aws.amazon.com/windows/">run Microsoft Windows Server and Microsoft SQL Server on the EC2 platform</a> later this fall.  This announcement is a huge step and will allow customers to <a href="http://www.allthingsdistributed.com/2008/09/amazon_ec2_with_microsoft_wind.html">deploy ASP.NET applications</a> using a host of database options as well as other Windows-based applications such as Windows Media transcoding.  This advancement in cloud computing will really ease the transition for potential enterprise clients which still tend to be very Windows heavy &#8211; ASP.NET portals still seem to be rather popular in my experience.</p>
<p>Last week, in an email to developers, they also announced that Oracle has certified EC2 as “the first cloud computing platform that has been authorized to run supported Oracle databases” which also increases the database options for enterprises and developers alike.  According to the announcement, <a href="http://aws.amazon.com/about-aws/whats-new/2008/09/22/oracle-and-aws/">customers will be able to run Oracle 11g</a>, Oracle Fusion Middleware and the Oracle Enterprise Manager on AWS.  Oracle is really taking an interest in the project and has delivered a set of free images to help make deployment easier.</p>
<p>I don&#8217;t claim to know how many &#8216;enterprise&#8217; clients Amazon Web Services has on its roster but I think this is really a step in the right direction.  I know enterprise security executives are still wary about throwing their proprietary data in the &#8216;cloud&#8217; but who wouldn&#8217;t enjoy a little extra cushion for those PR heavy days when your site gets overloaded.  I can only imagine how busy the Bear Sterns intranet was the day their employees found out it was over.</p>
<p>This will also continue to lower the barrier of entry for web-based start-ups.  The language of choice these days tends to be PHP, but that isn&#8217;t normally a part of the university curriculum.  Now, students can continue to expand on those class projects and turn them into successful (hopefully&#8230;) start-ups.  Of course, that&#8217;s only for those few that aren&#8217;t programming before they hit high school.</p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2008/10/05/amazon-brings-enterprise-databases-to-the-cloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apparently Intuit QuickBase Isn&#8217;t Dead</title>
		<link>http://nathanhjones.com/2008/07/03/apparently-intuit-quickbase-isnt-dead/</link>
		<comments>http://nathanhjones.com/2008/07/03/apparently-intuit-quickbase-isnt-dead/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 17:51:28 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[intuit]]></category>
		<category><![CDATA[platform]]></category>
		<category><![CDATA[quickbase]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/?p=78</guid>
		<description><![CDATA[Ok, so almost 3 months ago when TechCrunch wrote that Intuit (the makers of TurboTax, QuickBooks, Quicken, etc) were launching a development platform within QuickBase I signed up.  I thought it would be pretty cool to at least see what they were doing and I&#8217;m really into Enterprise software (small, medium or large enterprises are [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so almost 3 months ago when <a href="http://www.techcrunch.com/2008/04/16/watch-out-salesforce-intuit-opens-up-quickbase-to-developers/">TechCrunch wrote that Intuit</a> (the makers of TurboTax, QuickBooks, Quicken, etc) were launching a <a href="http://quickbase.intuit.com/">development platform within QuickBase</a> I signed up.  I thought it would be pretty cool to at least see what they were doing and I&#8217;m really into Enterprise software (small, medium or large enterprises are all the same to me &#8211; business is business no matter the size).</p>
<p>Well, after registering I didn&#8217;t get a confirmation email, a &#8220;thanks for registering&#8221; email or even a &#8220;you were rejected, better luck next time&#8221;.   I figured it was a good try, I guess I&#8217;m not getting that 5 minutes back.  Then yesterday, completely out of the blue, I get a note from QuickBase that  I&#8217;ve &#8220;been accepted into the <span class="nfakPe">Intuit</span> QuickBase Developer Program&#8221;.  Ok, well that&#8217;s cool but you may want to communicate a little better next time.  I figured some server troll somewhere ate my application.  Good thing you didn&#8217;t make me submit my password when I initially signed up or I would have been in trouble.</p>
<p>Anyways, I&#8217;ve completed the registration and I&#8217;m going to begin poking around what they have to offer.  At first glance it seems functional but not as visually pleasing as something I&#8217;d expect from Intuit.  It is in Beta though so I won&#8217;t give them too hard of a time.</p>
<p>More to come on QuickBase in the near future.  Maybe if I can find a few hours I&#8217;ll get an example application up.</p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2008/07/03/apparently-intuit-quickbase-isnt-dead/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Needed Gmail Enhancements</title>
		<link>http://nathanhjones.com/2008/03/25/needed-gmail-enhancements/</link>
		<comments>http://nathanhjones.com/2008/03/25/needed-gmail-enhancements/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 03:15:08 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[enhancements]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google docs]]></category>
		<category><![CDATA[google reader]]></category>
		<category><![CDATA[google talk]]></category>
		<category><![CDATA[picasa]]></category>

		<guid isPermaLink="false">http://nathanhjones.com/2008/03/25/needed-gmail-enhancements/</guid>
		<description><![CDATA[As I&#8217;ve stated several times, I love the various Google products and use several of them on a daily basis. My Gmail is open almost all day long, I use Google Reader to sort, manage and read my news, I share photos and documents with Picasa and Google Docs and I communicate with people all [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve stated several times, I love the various Google products and use several of them on a daily basis.  My Gmail is open almost all day long, I use Google Reader to sort, manage and read my news, I share photos and documents with Picasa and Google Docs and I communicate with people all over the world (literally) with Google Talk.  When I start my own business I&#8217;ll probably use <a href="http://www.google.com/a/help/intl/en/index.html">Google Apps</a> to keep costs low and because it allows me the ability to use the Gmail web interface and it&#8217;s easy to install.  Simply put, they have created an amazing suite of free services but as my usage grows, so does the need for a few enhancements to make things even better.</p>
<p>Since Gmail released the IMAP feature a few months ago I&#8217;ve been a pretty happy camper.  While I&#8217;m pretty happy, there is always room for improvement.  I think Gmail recognizes that since they&#8217;re continually releasing new features!  Keep it up guys.</p>
<ul>
<li> <strong>Tagging:</strong> The ability to label emails with several tags is great but having to select them from a drop down list is inefficient.  It would be great if there was a type-ahead feature that auto-completed tags as I began typing them.  It would also be great if you could apply multiple tags to filters.</li>
<li><strong>Filtering:</strong> Gmail has a great filter set-up but there is one thing I&#8217;d like to see added.  The ability to apply multiple tags to filtered messages.  Some people may not use tags to quite the same extent I do but I like to keep an organized mailbox.  With my travels for work I also like to make sure I keep as many records as possible and there are some emails that I get on a regular basis that I like filtered into two buckets.  Hotel receipts are the main culprit (expense reporting can be such a pain).  Currently, I just have to filter it with one tag and add the second manually.  Not a huge deal, but it would definitely be a time saver.</li>
<li><strong>Shortcut Keys:</strong> For those of us that use Outlook all day for corporate email, shortcut keys are where it&#8217;s at.  I can successfully navigate almost all of Outlook (that I use at least) without touching the mouse.  Google has done a pretty good job building out the shortcut keys but some of them are counter-intuitive.  Maybe the problem is they just aren&#8217;t intuitive based on the Windows habits that we have all picked up.  I&#8217;d like to see the ability to customize your shortcut keys or at least add a few more like &#8216;ALT+s&#8217; to quickly send an email from compose mode.</li>
</ul>
<p>If I new anything about writing <a href="http://www.greasespot.net/">GreaseMonkey</a> scripts or had a couple hours of extra time I would consider writing a couple of these enhancements myself.  But&#8230;since I don&#8217;t and I have no extra time I&#8217;m hoping the various Google teams go ahead and step-up.</p>
<p>These are obviously just my opinions but I think they&#8217;re enhancements that would benefit the masses.</p>
]]></content:encoded>
			<wfw:commentRss>http://nathanhjones.com/2008/03/25/needed-gmail-enhancements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

