<?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>musicalgeometry &#187; iPhone</title>
	<atom:link href="http://www.musicalgeometry.com/archives/category/iphone/feed" rel="self" type="application/rss+xml" />
	<link>http://www.musicalgeometry.com</link>
	<description>sound, code, &#38; DIY tech</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:32:17 +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>Plug-And-Play OpenAL / AVFoundation Sound Engine For iPhone Apps</title>
		<link>http://www.musicalgeometry.com/archives/912</link>
		<comments>http://www.musicalgeometry.com/archives/912#comments</comments>
		<pubDate>Thu, 25 Feb 2010 21:17:47 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=912</guid>
		<description><![CDATA[I recently found a great sound engine for iPhone applications that is pretty much plug-and-play. This sound engine was written by Alex Restrepo under a creative commons attribution-share alike licence, so you are free to use it so long as &#8230; <a href="http://www.musicalgeometry.com/archives/912">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently found a great sound engine for iPhone applications that is pretty much plug-and-play.</p>
<div id="attachment_913" class="wp-caption alignnone" style="width: 510px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/02/openal.jpg"><img class="size-full wp-image-913 " style="border: 1px solid black;" title="openal" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/openal.jpg" alt="" width="500" height="268" /></a><p class="wp-caption-text">OpenAL lets you play multiple sounds at once</p></div>
<p>This sound engine was written by <a href="http://homepage.mac.com/alexrestrepo/indexmain.html">Alex Restrepo</a> under a creative commons attribution-share alike licence, so you are free to use it so long as you attribute the code to the author and if you change it and share it you must do so under the same license.  I have corrected one small mistake (a semi-colon where it should not have been) and also edited the formatting of the code to my personal preference. You can get an Xcode example project that uses the sound engine <a href="http://www.jasonjob.net/share/SoundEngineExample.zip">here</a>. If you just want the sound engine itself you can get it <a href="http://www.jasonjob.net/share/SoundEngine.zip">here</a>.  If you look at the <a href="http://www.jasonjob.net/share/SoundEngineExample.zip">example project</a> you will see how easy this sound engine is to use. It provides simple methods for playing and managing background music and for playing sound effects on top. These classes use AVFoundation to play the background music and OpenAL to play other sounds on top. I am not informed enough about either of these to know what advantages or disadvantages this may offer but will look into it and possibly do a pure OpenAL version.  To add the sound engine to your own project just add the class files included in <a href="http://www.jasonjob.net/share/SoundEngine.zip">SoundEngine.zip</a> to your project. Also be sure to add the OpenAL.framework, AVFoundation.framework and the AudioToolbox.framework otherwise you will get a host of strange errors.  You have the option of using the CMOpenALSoundManager as a singleton. If you do use it as a singleton (you can do this by setting USE_AS_SINGLETON to 1 at the top of CMOpenALSoundManager.h) you just need to initialize it somewhere in your code with:</p>
<pre><code>[[CMOpenALSoundManager sharedCMOpenALSoundManager] init];</code></pre>
<p>You also need to enumerate the tags for your sounds (ideally somewhere that every class that needs them will have access to them):</p>
<pre><code>enum mySoundIds {
BUTTONSOUND1
        BUTTONSOUND2
        SUCCESSSOUND
        ERRORSOUND
};</code></pre>
<p>You can then add your sound effects by passing an array of sound file names like so:</p>
<pre><code>[CMOpenALSoundManager sharedCMOpenALSoundManager].soundFileNames = mySoundFileNamesArray;</code></pre>
<p>To access your sound manager from anywhere in your project make sure you have included the CMOpenSoundManager header file and then reference the sound manager with:</p>
<pre><code>[CMOpenALSoundManager sharedCMOpenALSoundManager]</code></pre>
<p>Here is an example of playing some background music and then playing a sound effect:</p>
<pre><code>[[CMOpenALSoundManager sharedCMOpenALSoundManager] playBackgroundMusic:@"backgroundLoop.m4a"];
[[CMOpenALSoundManager sharedCMOpenALSoundManager] playSoundWithID:BUTTONSOUND1];</code></pre>
<p>One thing that I am not satisfied about with this system is the need for the enumeration. The reason being that you need to know which order the sounds are going to be loaded so that the correct sounds match the correct enum value. A better way in my opinion would be to use NSString keys, so that when you load a sound, you also pass a key. This is the approach taken in the code on the <a href="http://www.gehacktes.net/2009/03/iphone-programming-part-6-multiple-sounds-with-openal/">gethacktes.net</a> blog, which is another great resource for OpenAL on the iPhone. Doing it this way allows you to lazy load sounds in any order. If I make that change I will be sure to post it here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/912/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode Script For Creating Properties From Instance Variables For UIViewController</title>
		<link>http://www.musicalgeometry.com/archives/904</link>
		<comments>http://www.musicalgeometry.com/archives/904#comments</comments>
		<pubDate>Wed, 24 Feb 2010 07:26:29 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=904</guid>
		<description><![CDATA[One of my favourite blogs on the net is Matt Gallagher&#8217;s Cocoa with Love. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a &#8230; <a href="http://www.musicalgeometry.com/archives/904">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my favourite blogs on the net is Matt Gallagher&#8217;s <a href="http://cocoawithlove.com/">Cocoa with Love</a>. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a couple of years ago.</p>
<div id="attachment_905" class="wp-caption alignnone" style="width: 637px"><a href="http://cocoawithlove.com/"><img class="size-full wp-image-905 " style="border: 1px solid black;" title="cocoawithlove" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/cocoawithlove.png" alt="" width="627" height="139" /></a><p class="wp-caption-text">A fantastic resource for Cocoa, Objective-C and programming in general</p></div>
<p>The script called <a href="http://projectswithlove.com/projects/PropertyFromInstanceVariable.zip">PropertyFromInstanceVariable</a> had already been added to by a couple of other people, Yung-Luen Lan &amp; <a href="http://github.com/mschrag/xcode_property_from_ivar">Mike Schrag</a> and <a href="http://www.bernard-web.com/pierre/blog/">Pierre Bernard</a> and I have now shaped it for my own specific needs, and possibly yours too.</p>
<p>The tedium I was trying to eliminate was the process of creating Objective-C properties from instance variables and doing basic memory management on them. This is a repetitive process that seems more appropriate to hand off to the machine.</p>
<p>Matt&#8217;s script allows you to take an instance variable defined in your interface file and automatically create a property for it, synthesize the property in the implementation, add a release statement and set the property to NULL in the dealloc method.</p>
<p>For example, running the script on this:</p>
<pre><code>NSString *myString;</code></pre>
<p>would automatically create this in the interface:</p>
<pre><code>@property (nonatomic, retain) NSString *myString;</code></pre>
<p>this at the top of the implementation:</p>
<pre><code>@synthesize myString;</code></pre>
<p>and adds these two lines to the dealloc method:</p>
<pre><code>[myString release];
myString = NULL;</code></pre>
<p>Because this script was written before the viewDidUnload method had been added to the UIViewController class it didn&#8217;t make use of the viewDidUnload method. I wanted to update it to set the retaining references to subviews in the view hierarchy to nil. These reference properties may have been set through IBOutlets when loading a nib or programmatically in the loadView method.</p>
<p>I have now modified the script to reflect my own coding habits. It still creates the property, synthesizes it and adds a release to the dealloc method, but if the class is a subclass of UIViewController then this is placed in viewDidUnload like so:</p>
<pre><code>self.myString = nil;</code></pre>
<p>This script can be run on multiple instance variables at once and greatly cuts down on the time it takes to set up a new class. Instructions on installing the script can be found <a href="http://cocoawithlove.com/2008/12/instance-variable-to-synthesized.html">here</a>.</p>
<p>You can get my fork of the script on <a href="http://github.com/jj0b/xcode_property_from_ivar">github</a>.</p>
<p>NOTE: I have updated to script and edited this post to reflect those changes. All links are to the most recent version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/904/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>c74: iPhone/iPod Touch Max 5 External</title>
		<link>http://www.musicalgeometry.com/archives/894</link>
		<comments>http://www.musicalgeometry.com/archives/894#comments</comments>
		<pubDate>Fri, 12 Feb 2010 07:32:53 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[MaxMSP]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=894</guid>
		<description><![CDATA[Just downloaded a new app that allows you to create custom Max 5 interfaces on your iPhone or iPod Touch.  This looks to me like a great creative tool and the best touch software option on a mobile platform for users &#8230; <a href="http://www.musicalgeometry.com/archives/894">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just downloaded a new app that allows you to create custom Max 5 interfaces on your iPhone or iPod Touch.  This looks to me like a great creative tool and the best touch software option on a mobile platform for users of Cycling &#8217;74&#8242;s MaxMSP. c74 is integrated with Max 5, so you will need to be a Max 5 owner to use it.</p>
<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/02/mainscreen.jpg"><img class="alignnone size-full wp-image-895" style="border: 1px solid black;" title="mainscreen" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/mainscreen.jpg" alt="" width="200" height="300" /></a><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/02/c74.jpg"><img class="alignnone size-full wp-image-896" style="border: 1px solid black;" title="c74" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/c74.jpg" alt="" width="200" height="300" /></a><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/02/screen3.jpg"><img class="alignnone size-full wp-image-897" style="border: 1px solid black;" title="screen3" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/screen3.jpg" alt="" width="200" height="300" /></a></p>
<p>From the <a href="http://www.nr74.org/about.html">nr74website</a>:</p>
<p>c74 is an iPhone / iPod Touch app that let&#8217;s you connect your device with Cycling &#8217;74&#8242;s Max/MSP 5.</p>
<p>The massive improvement over existing interface layout apps is that the layout is dynamically controlled by Max. Therefore we can have the interface adapt to the tasks it has to perform in real-time.</p>
<p>In order to connect this app to Max please download the free external from : <a title="http://www.nr74.org/c74/c74.zip" href="http://www.nr74.org/c74/c74.zip">http://www.nr74.org/c74/c74.zip</a>(requires osx 10.5 or higher !)</p>
<p>Custom controller interfaces are built straight from within Max, presets can be stored etc. The external features some nice attributes for receiving accelerometer, GPS, compass, shake gesture and proximity data.</p>
<p>Please note : the c74 app won’t run on 1st gen iPods</p>
<p>Please note : the c74 external requires osx 10.5 or higher</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/kcDjlwqs238&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/kcDjlwqs238&amp;rel=0&amp;color1=0xb1b1b1&amp;color2=0xcfcfcf&amp;hl=en_US&amp;feature=player_embedded&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Looking forward to playing with this. Nice work n74!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/894/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When To Use self.myObject Instead Of myObject In iPhone Programming</title>
		<link>http://www.musicalgeometry.com/archives/872</link>
		<comments>http://www.musicalgeometry.com/archives/872#comments</comments>
		<pubDate>Mon, 25 Jan 2010 18:36:52 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=872</guid>
		<description><![CDATA[I have seen a lot of confusion on the topic of when and why to reference an object using self.myObject versus just plain myObject. It took me a while to understand this myself, and please, if I am mistaken in &#8230; <a href="http://www.musicalgeometry.com/archives/872">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have seen a lot of confusion on the topic of when and why to reference an object using self.myObject versus just plain myObject. It took me a while to understand this myself, and please, if I am mistaken in my explanation, set me right, but here it is as I understand it.</p>
<div id="attachment_878" class="wp-caption alignnone" style="width: 310px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2010/01/objective_c.jpg"><img class="size-medium wp-image-878 " style="border: 1px solid black;" title="objective_c" src="http://www.musicalgeometry.com/wp-content/uploads/2010/01/objective_c-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">Apparently some people don&#39;t like Objective-C</p></div>
<p>If you reference an object in your implementation that you declared in your header with @property and then used @synthesize in your implementation to automatically create getter and setter methods for the object, then using self.myObject  = newObject will call the setter and references to self.myObject will call the getter. As far as I know, if you are just referencing your object you don&#8217;t need to use the getter unless you are trying to distinguish from an object with the same name. When you assign your object however, the distinction becomes very important because everywhere you write:</p>
<pre><code>self.myObject = newObject;</code></pre>
<p>you are actually sending the message:</p>
<pre><code>[self setMyObject:newObject];</code></pre>
<p>which under the hood looks like:</p>
<pre><code>objc_msgSend(self, @selector(setMyObject:), newObject);</code></pre>
<p>The consequence of using self.myObject in this way is that myObject will use whatever retain property you set in the @property declaration. So if you set up myObject like so:</p>
<pre><code>@property (nonatomic, retain) MyObjectClass *myObject;</code></pre>
<p>then the value of myObject will be retained even after newObject has been deallocated.</p>
<p>If instead you had assigned myObject like this:</p>
<pre><code>myObject = newObject;</code></pre>
<p>then myObject is just the same as newObject. Therefore if newObject is deallocated then myObject will be pointing to a meaningless memory address. Probably not what you want.</p>
<p>So, here is an example:</p>
<pre><code>.h file
...
UIView *myUIView;
...
@property (nonatomic, retain) UIView *myUIView;
...

.m file
...
@synthesize myUIView;
...
// Get frame:
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

// Set up myUIView:
UIView *tempUIView = [[UIView alloc] initWithFrame:applicationFrame];
tempUIView.backgroundColor = [UIColor blackColor];
self.myUIView = tempUIView;
[tempUIView release];
...</code></pre>
<p>At this point in the code myUIView is now set up and ready to use. Because I used the setter to assign myUIView it is unaffected when I release tempUIView. If I had forgotten to use self.myUIView for the assignment then I would be unable to use myUIView later in the program.</p>
<p>Hope that clears things up for some of you. Please comment if I have something wrong or if you can help make things even clearer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/872/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Camera Overlay App With Custom Button Example</title>
		<link>http://www.musicalgeometry.com/archives/821</link>
		<comments>http://www.musicalgeometry.com/archives/821#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:26:37 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=821</guid>
		<description><![CDATA[There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or &#8230; <a href="http://www.musicalgeometry.com/archives/821">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or data on a camera view). I wasn&#8217;t satisfied with the few examples I found on the topic so I decided to try one myself. I will endeavour to make it as clear as I can and show you how to make a custom button while I am at it, but I do assume a basic knowledge of Objective-C and iPhone app development in Xcode.</p>
<div id="attachment_823" class="wp-caption alignnone" style="width: 210px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38.png"><img class="size-medium wp-image-823 " style="border: 1px solid black;" title="Screenshot 2009.12.10 18.46.38" src="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38-200x300.png" alt="OverlayViewTester screenshot" width="200" height="300" /></a><p class="wp-caption-text">OverlayViewTester screenshot</p></div>
<p>So first I will describe the OverlayViewTester app. Basically it just overlays some cool looking red selection braces on a camera view and has a button that when pressed performs a &#8216;scan&#8217; for two seconds and lets you know by adding a &#8220;Scanning&#8230;&#8221; label at the top of the screen during that time. So really it does nothing, but it looks good and is a good first step to making a more fun and interesting interactive camera overlay app.</p>
<p>To get started download the source code from <a href="http://github.com/jj0b/OverlayViewTester">GitHub</a>. Next I will go through the files in the project and present the juicy bits. Consult the source code you downloaded for the full meal deal.</p>
<p><strong>OverlayViewTesterApDelegate</strong></p>
<p>Taking a look at the project we start with a typical app delegate, OverlayViewTesterAppDelegate which loads the OverlayViewController. Nothing monumental there so I won&#8217;t bother reproducing it here.</p>
<p><strong>OverlayViewController</strong></p>
<p>Now on to the OverlayViewController where we create the camera view.</p>
<p>In the interface, <em>OverlayViewController.h</em>: we define some constants:</p>
<pre><code>// Transform values for full screen support:
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.12412

// iPhone screen dimensions:
#define SCREEN_WIDTH  320
#define SCREEN_HEIGTH 480</code></pre>
<p>In the implementation, <em>OverlayViewController.m</em> there is a bit of a GOTCHA. The line</p>
<pre><code>[self presentModalViewController:picker animated:YES];</code></pre>
<p>must be called in  <em>viewDidAppear:</em> not in a <em>viewDidLoad:</em> method. Here it is:</p>
<pre><code>- (void) viewDidAppear:(BOOL)animated {
    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];

    // Create a new image picker instance:
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    // Set the image picker source:
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Hide the controls:
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;

    // Make camera view full screen:
    picker.wantsFullScreenLayout = YES;
    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

    // Insert the overlay:
    picker.cameraOverlayView = overlay;

    // Show the picker:
    [self presentModalViewController:picker animated:YES];
    [picker release];

    [super viewDidAppear:YES];
}</code></pre>
<p>I think the comments make it clear what is going on there.</p>
<p><strong>OverlayView</strong></p>
<p>Next lets look at the custom subclass of UIView called OverlayView. This is where we actually create our overlay.</p>
<p>In the interface, <em>OverlayView.h</em> we declare two new methods:</p>
<pre><code>- (void)scanButtonTouchUpInside;
- (void)clearLabel:(UILabel *)label;</code></pre>
<p>Here are the important parts of the implementation, <em>OverlayView.m</em>:</p>
<pre><code>- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Clear the background of the overlay:
	self.opaque = NO;
	self.backgroundColor = [UIColor clearColor];

	// Load the image to show in the overlay:
	UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
	UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
	overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
	[self addSubview:overlayGraphicView];
	[overlayGraphicView release];

	ScanButton *scanButton = [[ScanButton alloc] initWithFrame:CGRectMake(130, 320, 60, 30)];

	// Add a target action for the button:
	[scanButton addTarget:self action:@selector(scanButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:scanButton];
    }
    return self;
}

- (void) scanButtonTouchUpInside {
    UILabel *scanningLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 120, 30)];
    scanningLabel.backgroundColor = [UIColor clearColor];
    scanningLabel.font = [UIFont fontWithName:@"Courier" size: 18.0];
    scanningLabel.textColor = [UIColor redColor];
    scanningLabel.text = @"Scanning...";

    [self addSubview:scanningLabel];

    [self performSelector:@selector(clearLabel:) withObject:scanningLabel afterDelay:2];

    [scanningLabel release];
}

- (void)clearLabel:(UILabel *)label {
    label.text = @"";
}</code></pre>
<p>Notice that we have used an instance of ScanButton which we will get to next. When the ScanButton detects a UIControlEventTouchUpInside it calls the scanButtonTouchUpInside method which places a label on the screen for 2 seconds.</p>
<p><strong>ScanButton</strong></p>
<p>So finally we are left with our ScanButton. You might think that for a custom button we would subclass UIButton, but unless you really want to use the UIBUtton method setTitle:ForState it is recommended that you subclass UIControl. It will save you a world of hurt.</p>
<p>Here is the interface, <em>ScanButton.h</em>:</p>
<pre><code>#import &lt;Foundation/Foundation.h&gt;

@interface ScanButton : UIControl {
}

- (void)buttonPressed;

@end</code></pre>
<p>I put the buttonPressed method in here for future use. It is meant to be used to change things related to the button itself and not the actions associated with the button in the OverlayViewController. You could for example use it to have the button&#8217;s image or state or both toggle.</p>
<p>Last but not least we have the implementation, <em>ScanButton.m</em>:</p>
<pre><code>#import "ScanButton.h"

@implementation ScanButton

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
	// Set button image:
	UIImageView *buttonImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
	buttonImage.image = [UIImage imageNamed:@"scanbutton.png"];

	[self addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside]; // for future use

        [self addSubview:buttonImage];
    }
    return self;
}

- (void)buttonPressed {
    // TODO: Could toggle a button state and/or image
}

@end</code></pre>
<p>So there you have it. A custom camera overlay and a custom button. I hope that with this code you will be well on your way to writing much more useful, interesting and creative apps than this example. Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/821/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>iWasHere iPhone App Free For A Limited Time</title>
		<link>http://www.musicalgeometry.com/archives/638</link>
		<comments>http://www.musicalgeometry.com/archives/638#comments</comments>
		<pubDate>Wed, 26 Aug 2009 16:29:54 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=638</guid>
		<description><![CDATA[I have made my iPhone app iWasHere free for a limited time to encourage more users to start creating networks with their friends. Augment your reality with iWasHere! iWasHere is a geo-locational social networking message board. iWasHere allows you to &#8230; <a href="http://www.musicalgeometry.com/archives/638">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere.jpg"><img style="border: 0px initial initial;" title="iwashere" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere-50x50.jpg" alt="iwashere" width="50" height="50" /></a></p>
<p>I have made my iPhone app <a href="http://www.musicalgeometry.com/iwashere">iWasHere</a> free for a limited time to encourage more users to start creating networks with their friends.</p>
<div id="attachment_455" class="wp-caption alignnone" style="width: 218px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/addview1.jpg"><img class="size-medium wp-image-455" title="addview" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/addview1-208x300.jpg" alt="Creating a new network" width="208" height="300" /></a><p class="wp-caption-text">Creating a new network</p></div>
<p>Augment your reality with iWasHere!</p>
<p>iWasHere is a geo-locational social networking message board. iWasHere allows you to create an augmented reality by enabling you to leave a message at a specific location which can then only be read at that location. You can write to a Public network that is readable and writable by everyone, or you can create your own private networks for just you and your friends.</p>
<p>Use iWasHere to leave a note for a friend at a bus stop, outside their work or in a park. Read or write reviews of stores and restaurants right outside their doors. Make a virtual community message board in your neighborhood. Hide directions to a secret party or a surprise proposal. Create a treasure hunt that uses virtual clues or do virtual geocaching. iWasHere can be whatever you want it to be. The only limit is your imagination!</p>
<p>Get it while it is free!</p>
<p><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8"><img style="border: 0px initial initial;" title="marketing_badge" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/marketing_badge.png" alt="marketing_badge" width="121" height="41" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/638/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving JSON Data In iPhone Apps</title>
		<link>http://www.musicalgeometry.com/archives/571</link>
		<comments>http://www.musicalgeometry.com/archives/571#comments</comments>
		<pubDate>Sat, 15 Aug 2009 04:28:14 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[online]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=571</guid>
		<description><![CDATA[As described at www.json.org, JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. The JSON format is one of two things; a list &#8230; <a href="http://www.musicalgeometry.com/archives/571">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As described at <a href="http://www.json.org/">www.json.org</a>, JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. The JSON format is one of two things; a list of name/value pairs that can be realized as an object, record, struct, dictionary, hash table, keyed list, or associative array or an ordered list of values which in most languages is realized as an array, vector, list, or sequence.</p>
<div id="attachment_606" class="wp-caption alignnone" style="width: 170px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/08/json160.gif"><img class="size-full wp-image-606 " style="border: 1px solid black;" title="json160" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/json160.gif" alt="JSON logo" width="160" height="160" /></a><p class="wp-caption-text">JSON logo</p></div>
<p>The JSON format is often used as an alternative to <a href="http://en.wikipedia.org/wiki/XML">XML</a> to transmit structured data over a network, its biggest use being in <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">Ajax</a> web application programming.</p>
<p>Below are instructions for how to retrieve and parse JSON formatted data in an iPhone app.</p>
<p><strong>Adding JSON Framework To Your XCode Project</strong></p>
<p>To use JSON in an iPhone app you first need to download the JSON Framework for Objective-C from its <a href="http://code.google.com/p/json-framework/downloads/list">Google Code page</a>.</p>
<p>When it is downloaded, mount the DMG.</p>
<p>Finally, drag and drop the JSON directory onto the <em>Classes</em> folder icon in the <em>Groups &amp; Files</em> panel in XCode.</p>
<p><strong>Retrieving JSON Data</strong></p>
<p>First of all make sure that you include the JSON.h file in your implementaion(your .m file):</p>
<pre><code>#import "JSON.h"</code></pre>
<p>To retrieve JSON data use an NSURLConnection to issue an HTTP request. To do this you will need an <code>NSMutableData</code> variable to hold the response data. Create it in the interface (.h file) with:</p>
<pre><code>NSMutableData *responseData;</code></pre>
<p>and</p>
<pre><code>@property (nonatomic, retain) NSMutableData *responseData;</code></pre>
<p>and don&#8217;t forget to synthesize in the implementation (.m file):</p>
<pre><code>@synthesize responseData;</code></pre>
<p>Next you need to make an HTTP request with NSURLConnection so start by initializing responseData:</p>
<pre><code>responseData = [[NSMutableData data] retain];</code></pre>
<p>Then make the request:</p>
<pre><code>NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.someurl.com/somefile.json"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];</code></pre>
<p>Then you need to include the following methods to process the NSURLConnection and save the JSON data into the responseData variable:</p>
<pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	[responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
	[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
	label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}</code></pre>
<p><strong>Making Use Of The JSON Data</strong></p>
<p>To make use of the JSON data use the connectionDidFinishLoading: method. Here is an example with some simple error checking:</p>
<pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	[connection release];

	NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
	[responseData release];

	if ([responseString isEqualToString:@"\"Unable to find specified resource.\""]) {
		NSLog(@"Unable to find specified resource.\n");
	} else {
		NSDictionary *dictionary = [responseString JSONValue];
		self.someVariable = [dictionary valueForKey:@"somekey"];
	}
}</code></pre>
<p>In this connectionDidFinishLoading: method you can use any of the key names you know to be in the JSON data to get their values and store them or use them as you need.</p>
<p>Hopefully this helps you to get started using JSON data in your iPhone apps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/571/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iWasHere Now Available On The App Store</title>
		<link>http://www.musicalgeometry.com/archives/582</link>
		<comments>http://www.musicalgeometry.com/archives/582#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:54:21 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=582</guid>
		<description><![CDATA[Augment your reality with iWasHere! After a long wait my geo-locational social networking message board iPhone app iWasHere is finally available for purchase on the App Store. iWasHere is a geo-locational social networking message board. iWasHere allows you to create &#8230; <a href="http://www.musicalgeometry.com/archives/582">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere.jpg"><img class="size-thumbnail wp-image-451 alignnone" title="iwashere" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere-50x50.jpg" alt="iwashere" width="50" height="50" /></a></p>
<p>Augment your reality with iWasHere!</p>
<p>After a long wait my geo-locational social networking message board iPhone app <a href="http://www.musicalgeometry.com/iwashere">iWasHere</a> is finally available for purchase on the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8">App Store</a>.</p>
<div id="attachment_461" class="wp-caption alignnone" style="width: 218px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewview.jpg"><img class="size-medium wp-image-461 " style="border: 1px solid black;" title="viewview" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewview-208x300.jpg" alt="iWasHere view page" width="208" height="300" /></a><p class="wp-caption-text">iWasHere iPhone app</p></div>
<p>iWasHere is a geo-locational social networking message board. iWasHere allows you to create an augmented reality by enabling you to leave a message at a specific location which can then only be read at that location. You can write to a Public network that is readable and writable by everyone, or you can create your own private networks for just you and your friends.</p>
<p>Use iWasHere to leave a note for a friend at a bus stop,  outside their work or in a park. Read or write reviews of stores and restaurants right outside their doors. Make a virtual community message board in your neighborhood. Hide directions to a secret party or a surprise proposal. Create a treasure hunt that uses virtual clues or do virtual geocaching. iWasHere can be whatever you want it to be. The only limit is your imagination!</p>
<p><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8"><img style="border: 0px initial initial;" title="marketing_badge" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/marketing_badge.png" alt="marketing_badge" width="121" height="41" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/582/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PachubeMon Now Available On The App Store</title>
		<link>http://www.musicalgeometry.com/archives/559</link>
		<comments>http://www.musicalgeometry.com/archives/559#comments</comments>
		<pubDate>Fri, 07 Aug 2009 19:41:11 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[app]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[pachube]]></category>
		<category><![CDATA[prototyping]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=559</guid>
		<description><![CDATA[I am happy to announce that my Pachube feed organizer/viewer application PachubeMon is now available as a free download on the App Store. It was also announced on the Pachube blog on Monday. Pachube is a web service available at pachube.com &#8230; <a href="http://www.musicalgeometry.com/archives/559">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/pachubemonitorlogo.jpg"><img class="alignnone size-thumbnail wp-image-483" title="pachubemonitorlogo" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/pachubemonitorlogo-50x50.jpg" alt="pachubemonitorlogo" width="50" height="50" /></a></p>
<p>I am happy to announce that my Pachube feed organizer/viewer application <a href="http://www.musicalgeometry.com/pachubemon">PachubeMon</a> is now available as a free download on the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323811139&amp;mt=8">App Store</a>. It was also announced on the <a href="http://bit.ly/ky74u">Pachube blog</a> on Monday.</p>
<div id="attachment_487" class="wp-caption alignnone" style="width: 218px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewfeed.jpg"><img class="size-medium wp-image-487 " style="border: 1px solid black;" title="viewfeed" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewfeed-208x300.jpg" alt="PachubeMon iPhone app" width="208" height="300" /></a><p class="wp-caption-text">PachubeMon iPhone app</p></div>
<p>Pachube is a web service available at <a href="http://www.pachube.com">pachube.com</a> that enables you to connect, tag and share real time sensor data from objects, devices, buildings and environments around the world.</p>
<p style="text-align: left;">PachubeMon is a utility app for the iPhone that lets you manage and view your Pachube feeds all in one place. The main page allows you to add and remove feeds. By selecting a feed from the list you can view it. You can find feed IDs on the Pachube website <a href="http://www.pachube.com">here</a>.</p>
<p style="text-align: left;">For a fascinating deeper look at Pachube and the concepts around it, check out the amazing article and interview <a href="http://www.ugotrade.com/2009/01/28/pachube-patching-the-planet-interview-with-usman-haque/">here</a>.</p>
<p style="text-align: left;"><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323811139&amp;mt=8"><img class="alignnone size-full wp-image-619" title="marketing_badge" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/marketing_badge.png" alt="marketing_badge" width="121" height="41" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/559/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Test For An Internet Connection On The iPhone</title>
		<link>http://www.musicalgeometry.com/archives/523</link>
		<comments>http://www.musicalgeometry.com/archives/523#comments</comments>
		<pubDate>Fri, 24 Jul 2009 03:41:57 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=523</guid>
		<description><![CDATA[If you write an app that uses the internet then the Apple Human Interface Guidelines require that you check for a WiFi or Wireless Wide Area Network (cellular) connection and let the user know if they are not available. One &#8230; <a href="http://www.musicalgeometry.com/archives/523">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you write an app that uses the internet then the Apple Human Interface Guidelines require that you check for a WiFi or Wireless Wide Area Network (cellular) connection and let the user know if they are not available.</p>
<div id="attachment_538" class="wp-caption alignnone" style="width: 210px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/nofunctionscreen.jpg"><img class="size-medium wp-image-538 " style="border: 1px solid black;" title="nofunctionscreen" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/nofunctionscreen-200x300.jpg" alt="nofunctionscreen" width="200" height="300" /></a><p class="wp-caption-text">iTunes app with no WiFi</p></div>
<p>One reliable and easy way to test for this is to make use of the code in the Reachability sample project that Apple provides with XCode. Here is what you need to do:</p>
<ol>
<li>Add Reachability.h and Reachability.m from the sample project to your project</li>
<li>Add the SystemConfiguration.framework to your project</li>
<li>Use the following code in your project:</li>
</ol>
<pre><code>[[Reachability sharedReachability] setHostName:@"www.apple.com"];
NetworkStatus internetStatus = [[Reachability sharedReachability] remoteHostStatus];
if ((internetStatus != ReachableViaWiFiNetwork) &amp;&amp; (internetStatus != ReachableViaCarrierDataNetwork)) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
        message:@"An internet connection via WiFi or cellular network is needed to use this app."
        delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
} else {
    // do whatever your program does
}</code></pre>
<p>In the first line you can set setHostName: to whatever you like. A simple page on your server that just returns True works just fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/523/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
