<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>iPhone/Web 2.0 &#187; Objective-C</title>
	<atom:link href="http://www.chucksmith.de/topics/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chucksmith.de</link>
	<description>Musings about the web and iPhone by Chuck Smith</description>
	<lastBuildDate>Mon, 07 Jun 2010 10:08:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<!-- podcast_generator="podPress/8.8" -->
		<copyright>&#xA9; </copyright>
		<managingEditor>chuck@chucksmith.de ()</managingEditor>
		<webMaster>chuck@chucksmith.de()</webMaster>
		<category></category>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary>Musings about the web and iPhone by Chuck Smith</itunes:summary>
		<itunes:author></itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name></itunes:name>
			<itunes:email>chuck@chucksmith.de</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://www.chucksmith.de/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://www.chucksmith.de/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>iPhone/Web 2.0</title>
			<link>http://www.chucksmith.de</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Send a BOOL value from JavaScript to Objective-C</title>
		<link>http://www.chucksmith.de/2009/04/send-bool-value-from-javascript-to-objective-c/</link>
		<comments>http://www.chucksmith.de/2009/04/send-bool-value-from-javascript-to-objective-c/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 10:11:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.chucksmith.de/?p=159</guid>
		<description><![CDATA[I&#8217;m developing an iPhone app which has a built-in quiz which runs using JavaScript within a UIWebView.  After a user clicks a Check Answers button, I have to use JavaScript to determine if all the answers are correct, so I can save this result for later.
Here is the relevant JavaScript:

function checkAnswers() {
  // [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m developing an iPhone app which has a built-in quiz which runs using JavaScript within a UIWebView.  After a user clicks a <i>Check Answers</i> button, I have to use JavaScript to determine if all the answers are correct, so I can save this result for later.</p>
<p>Here is the relevant JavaScript:</p>
<pre>
function checkAnswers() {
  // Do stuff to see if all answers were correct
  ...

  // Send all correct status back to Objective-C
  window.location = "/allCorrect/" + allCorrect;
}
</pre>
<p>In Objective-C, you then need to set up a UIWebViewDelegate to intercept whenever a new URL is to be loaded into the UIWebView.  Then you need to call <i>shouldStartLoadWithRequest</i> and if you called your fake URL, then it shouldn&#8217;t load, but execute the code you need to run in Objective-C instead.  Here is the relevant Objective-C code:</p>
<pre>
- (BOOL)webView:(UIWebView *)webView
        shouldStartLoadWithRequest:(NSURLRequest *)request
        navigationType:(UIWebViewNavigationType)navigationType {

  if ( [request.mainDocumentURL.relativePath
        isEqualToString:@"/allCorrect/false"] ) {
    NSLog( @"Nope, that is not right!" );
    return false;
  }

  if ( [request.mainDocumentURL.relativePath
        isEqualToString:@"/allCorrect/true"] ) {
    NSLog( @"You got them all!" );
    return false;
  }

  return true;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chucksmith.de/2009/04/send-bool-value-from-javascript-to-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save data to a file for next iPhone app launch</title>
		<link>http://www.chucksmith.de/2009/03/save-data-to-a-file-for-next-iphone-app-launch/</link>
		<comments>http://www.chucksmith.de/2009/03/save-data-to-a-file-for-next-iphone-app-launch/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 23:55:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.chucksmith.de/?p=110</guid>
		<description><![CDATA[Many times you need to save some user preferences or session data that will load automatically upon the next launch of your iPhone app.  Unfortunately this is quite a bit harder than it looks.  Here are simple steps on how to save a string from your application.  Just change the variable type [...]]]></description>
			<content:encoded><![CDATA[<p>Many times you need to save some user preferences or session data that will load automatically upon the next launch of your iPhone app.  Unfortunately this is quite a bit harder than it looks.  Here are simple steps on how to save a string from your application.  Just change the variable type to save more information!</p>
<p>Let&#8217;s assume you want to save the user&#8217;s account number.</p>
<p>Add the following to AppDelegate.h like you would normally create a mutable string:<br />
<code><br />
NSMutableString *accountName;<br />
@property (nonatomic, retain) NSMutableString *accountName;<br />
</code></p>
<p>Add the following to the top of AppDelegate.m.  I put this between my import and implementation statements.<br />
<code><br />
NSString *kAccountName = @"AccountName";<br />
</code></p>
<p>Add the following to applicationDidFinishLoading in AppDelegate.m:<br />
<code><br />
NSMutableString *tempMutableAccountName = [[[NSUserDefaults standardUserDefaults] objectForKey:kAccountName] mutableCopy];<br />
self.accountName = tempMutableAccountName;<br />
[tempMutableAccountName release];<br />
</code></p>
<p>Add the following to applicationWillTerminate in AppDelegate.m:<br />
<code><br />
[[NSUserDefaults standardUserDefaults] setObject:accountName  forKey:kAccountName];<br />
</code></p>
<p>In the application itself, you will need to add the following code where you want to set this value to prepare for saving on application termination:<br />
<code><br />
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];<br />
appDelegate.accountNumber = x;<br />
</code></p>
<p>To grab this value from the saved variable, add these lines:<br />
<code><br />
MobilePOSAppDelegate *appDelegate = (MobilePOSAppDelegate *)[[UIApplication sharedApplication] delegate];<br />
x = appDelegate.accountNumber;<br />
</code></p>
<p>Now you can save data from your app so it can be loaded automatically next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chucksmith.de/2009/03/save-data-to-a-file-for-next-iphone-app-launch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
