<?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>corprewland &#187; iphone</title>
	<atom:link href="http://www.corprew.org/blog/tag/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.corprew.org</link>
	<description>(dis)information organization</description>
	<lastBuildDate>Thu, 04 Feb 2010 20:48:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Authlogic and the iPhone</title>
		<link>http://www.corprew.org/blog/2010/01/27/authlogic-and-objectiveresource/</link>
		<comments>http://www.corprew.org/blog/2010/01/27/authlogic-and-objectiveresource/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 00:45:45 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
				<category><![CDATA[computer programming]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[defensive programming]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[ObjectiveResource]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[UserSession]]></category>

		<guid isPermaLink="false">http://www.corprew.org/?p=235</guid>
		<description><![CDATA[So, I&#8217;ve based a couple of apps on a combination of authlogic and the iPhone Objective Resource package, and when I mentioned this on the relevant lists I got a bunch of people asking me questions, so I thought I&#8217;d post about what I did generally. There are a couple of steps, most of which [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve based a couple of apps on a combination of <a href="http://github.com/binarylogic/authlogic">authlogic</a> and the iPhone <a href="http://iphoneonrails.com/">Objective Resource</a> package, and when I mentioned this on the relevant lists I got a bunch of people asking me questions, so I thought I&#8217;d post about what I did generally.</p>
<p>There are a couple of steps, most of which are geared towards having authlogic not produce redirects and instead produce http status codes that are interpretable to the applications.  Here&#8217;s an example of what I mean from my ApplicationController on an app</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> require_user
    <span style="color:#9966CC; font-weight:bold;">unless</span> current_user
      store_location
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You must be logged in to access this page&quot;</span>
      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#006600; font-weight:bold;">&#123;</span> redirect_to new_user_session_url <span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span>  <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;you must be logged in to access this page.&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:unauthorized</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In the default implementation of this filter, it always returns a redirect.  ObjectiveResource can follow the redirect (if you have a recent enough version), but it doesn&#8217;t really do it a lot of good.  This way, you get a status code that you can use.</p>
<p>Since Authlogic focuses on RESTful creation of things, a lot of operations map naturally.  To create an account on the Rails app, create a User object, and to test whether the user can log in, create a user session.  My application stores credentials between iPhone App invocations, so it creates a UserSession at startup if you have stored credentials.</p>

<div class="wp_syntax"><div class="code"><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>applicationDidFinishLaunching<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;">//</span>
<span style="color: #11740a; font-style: italic;">// ... blah blah blah all sorts of stuff removed.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
	UserPrefsManager<span style="color: #002200;">*</span> prefs <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UserPrefsManager sharedInstance<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>prefs isLoggedIn<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		UserSession <span style="color: #002200;">*</span> us <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UserSession alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
		us.login <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>prefs username<span style="color: #002200;">&#93;</span>;
		us.password <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>prefs password<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span> err <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</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>us createRemoteWithResponse<span style="color: #002200;">:&amp;</span>err<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;">//</span>
<span style="color: #11740a; font-style: italic;">//  ... my actual detection stuff removed and just the default left ...</span>
<span style="color: #11740a; font-style: italic;">//</span>
			<span style="color: #002200;">&#91;</span>AlertHelper showAlertWithError<span style="color: #002200;">:</span>err<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>prefs clearLogin<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#91;</span>ObjectiveResourceConfig setUser<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>prefs username<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>ObjectiveResourceConfig setPassword<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>prefs password<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">// ... and proceed on with your app's normal course of things ...</span>
<span style="color: #11740a; font-style: italic;">//	</span>
    <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>tabBarController.view<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>You see here that i&#8217;m creating an UserSession here and testing to see if it works and setting the ObjectiveResourceConfig properties if it does.  I have some logic where if there isn&#8217;t saved credentials you will get a dialog asking you to login or create an account (or whatever) later on, which is the point of <code>[prefs clearLogin];</code>.  This is matched by a change to the create method of the UserSessionController:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">format</span> <span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span> <span style="color:#9966CC; font-weight:bold;">do</span>
          flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Login successful!&quot;</span>
          redirect_back_or_default account_url
        <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span> <span style="color:#9966CC; font-weight:bold;">do</span>
          render <span style="color:#ff3333; font-weight:bold;">:xml</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user_session</span>, <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:created</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>(For brevity, I&#8217;ve just shown the successful branch)</p>
<p>This should be enough to get people going &#8212; all the other changes you have to make can be figured out from these two statements, and when I have some spare time I&#8217;m going to create a version of the demo application that works with ObjectiveResource.  The only other suggestion I have is to use the withResponse: versions of everything and code defensively, and note that in some versions of ObjectiveResource getting an error from your application will cause the application to throw.  In the meantime, feel free to ask me any questions</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2010/01/27/authlogic-and-objectiveresource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development</title>
		<link>http://www.corprew.org/blog/2008/04/08/iphone-development/</link>
		<comments>http://www.corprew.org/blog/2008/04/08/iphone-development/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 00:47:19 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
				<category><![CDATA[computer programming]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[bloggeroutragesyndrome]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone dev]]></category>

		<guid isPermaLink="false">http://www.corprew.org/blog/2008/04/08/iphone-development/</guid>
		<description><![CDATA[There have been a lot of people asking angry questions to Apple today because the Apple &#946; that they gave out to iPhone developers was timed to expire today and a lot of devs now have bricked their main mobile phone until an update appears. Lots of people appear angry, but they&#8217;re missing the main [...]]]></description>
			<content:encoded><![CDATA[<p>There have been a lot of people asking angry questions to Apple today because the Apple &beta; that they gave out to iPhone developers was timed to expire today and a lot of devs now have bricked their main mobile phone until an update appears.  Lots of people appear angry, but they&#8217;re missing the main issue for Apple:</p>
<blockquote><p><em>Dear Apple, why are you letting people this stupid into your &beta; programs</em></p></blockquote>
<p>People frequently forget what beta for software means in these days where everything is &beta; until people find a way to make money off of it.  It means untested, believed working properly but may blow up at any time, not ready for production.  So, I&#8217;m halfway between bemused and annoyed at the <a href="http://it.slashdot.org/it/08/04/08/1932232.shtml">outrage</a> that some folks seem to be fielding on various <a href="http://discussions.apple.com/thread.jspa?threadID=1476975&#038;tstart=0">fora</a>.</p>
<p>Also, calling a phone &#8216;bricked&#8217; when you can easily recover it by downloading new software hours later is hitting the epistemological puff pastry with a hammer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2008/04/08/iphone-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>writing code on the macintosh and its derivatives</title>
		<link>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/</link>
		<comments>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 02:10:20 +0000</pubDate>
		<dc:creator>corprew</dc:creator>
				<category><![CDATA[computer programming]]></category>
		<category><![CDATA[CoreData]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphone process model]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[ManagedObjectContext]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[ogm]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/</guid>
		<description><![CDATA[note that the latest revision of this blog&#8217;s theme seems to have introduced a weird bug with the code layout plugin (wp-syntax) on some browsers. i&#8217;m looking into it. I think the single most useful thing I&#8217;ve figured out recently in programming for MacOSX and the iPhone is this little snippet right here. - &#40;void&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><b>note that the latest revision of this blog&#8217;s theme seems to have introduced a weird bug with the code layout plugin (wp-syntax) on some browsers.  i&#8217;m looking into it.</b></p>
<p>I think the single most useful thing I&#8217;ve figured out recently in programming for MacOSX and the iPhone is this little snippet right here.</p>

<div class="wp_syntax"><div class="code"><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> updateListForEntityNamed<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> entityName andSearchString<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> queryString
<span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#91;</span>...<span style="color: #002200;">&#93;</span>
&nbsp;
	MyDocument<span style="color: #002200;">*</span> current <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDocumentController</span> sharedDocumentController<span style="color: #002200;">&#93;</span> currentDocument<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>current <span style="color: #002200;">&amp;&amp;</span> current <span style="color: #002200;">!=</span> self<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;CurrentDocument:%@ != self:%@&quot;</span>, current, self<span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#91;</span>current updateListForEntityNamed<span style="color: #002200;">:</span> entityName andSearchString<span style="color: #002200;">:</span> queryString<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">return</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#91;</span>...<span style="color: #002200;">&#93;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>What this does is intercept incoming messages that are supposed to go to the current window, and redirect them to that instance.  I&#8217;ve run into issues in Leopard (MacOSX 10.5) where this is an issue.  To some extent, this is probably a misconfiguration in interface builder somewhere, but it also an issue when using CoreData, because the <code>ManagedObjectContext</code>s are particular to instances of <code>NSManagedDocument</code>, and there are issues that arise if you end up using the wrong context.</p>
<p>I am slowly becoming a great fan of CoreData, it&#8217;s a great <a href="http://developer.apple.com/macosx/coredata.html">persistence/object-graph-management layer</a>.  More on this later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.corprew.org/blog/2008/03/12/writing-code-on-the-macintosh-and-its-derivatives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
