<?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>iPhone Programming Tutorials &#187; Marc Charbonneau</title>
	<atom:link href="/author/marc-charbonneau/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com</link>
	<description>iPhone Programming Tutorials</description>
	<lastBuildDate>Tue, 19 Nov 2013 19:34:46 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>How to import contacts into the iPhone Simulator</title>
		<link>http://icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/</link>
		<comments>http://icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 23:41:11 +0000</pubDate>
		<dc:creator><![CDATA[Marc Charbonneau]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Address Book]]></category>
		<category><![CDATA[AddressBook.framework]]></category>
		<category><![CDATA[Contacts]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=3614</guid>
		<description><![CDATA[If you&#8217;re working with AddressBook.framework chances are you&#8217;ll want to import your own data to test against when you&#8217;re in the simulator. Without being able to sync with iTunes or iCloud you may think you&#8217;re stuck entering in addresses manually; not only is that a huge pain, but there are probably lots of edge cases already in your address book you wouldn&#8217;t necessarily think of.
Fortunately there&#8217;s another option, with a tool called <a href="http://supercrazyawesome.com/">iPhone Backup Extractor</a>. Download it, run it  ...]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re working with AddressBook.framework chances are you&#8217;ll want to import your own data to test against when you&#8217;re in the simulator. Without being able to sync with iTunes or iCloud you may think you&#8217;re stuck entering in addresses manually; not only is that a huge pain, but there are probably lots of edge cases already in your address book you wouldn&#8217;t necessarily think of.</p>
<p>Fortunately there&#8217;s another option, with a tool called <a href="http://supercrazyawesome.com/">iPhone Backup Extractor</a>. Download it, run it and click Read Backups (note that you&#8217;ll need to back up to iTunes, not iCloud). Select your device, and you should see a list of apps included in your backup. Choose the last item on the list, iOS Files, and extract it to your desktop. When it&#8217;s done take a look in the folder it created. You should find two files in the folder <strong>iOS Files/Library/AddressBook</strong>, <strong>AddressBook.sqlitedb</strong> and <strong>AddressBookImages.sqlitedb</strong>.</p>
<p>Next, open the simulator&#8217;s Application Support folder (in the Finder menu, choose <strong>Go</strong> -&gt; <strong>Go to Folder&#8230;</strong>, enter <strong>~/Library/Application Support/iPhone Simulator</strong>, and choose the SDK you&#8217;re working with) and drill down to <strong>Library/AddressBook</strong>. Quit the simulator if it&#8217;s open, delete everything in this directory, then copy the two files noted above from your backup. That&#8217;s it! If everything went well the next time you launch the simulator you should see all your contacts.</p>
<p>Pretty easy, really. If address book data is a major feature of your app, you might even want to have a few trusted beta testers send you their backups so you can test with their contacts. My experience is that there are a lot of unusual or invalid contacts floating around on people&#8217;s phones, and the more opportunity you have to test the better you&#8217;ll do once you release your app.</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2011/11/09/how-to-import-contacts-into-the-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Disable the iPhone&#8217;s Front Camera</title>
		<link>http://icodeblog.com/2011/08/23/disable-the-iphones-front-camera/</link>
		<comments>http://icodeblog.com/2011/08/23/disable-the-iphones-front-camera/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 20:44:00 +0000</pubDate>
		<dc:creator><![CDATA[Marc Charbonneau]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iPhone Coding]]></category>
		<category><![CDATA[iphone programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=3334</guid>
		<description><![CDATA[The iPhone 4&#8242;s front camera is limited to 640&#215;480 resolution. Although handy for video conferencing, for some apps that&#8217;s to small to yield a usable photo. Unfortunately the UIImagePickerController class does not have an option to restrict the user from using the front camera. Although you can check the size of the photo after the user is finished, it&#8217;s not great user experience to reject it after they go through the entire process of taking a photo.
One option is to  ...]]></description>
				<content:encoded><![CDATA[<p>The iPhone 4&#8242;s front camera is limited to 640&#215;480 resolution. Although handy for video conferencing, for some apps that&#8217;s to small to yield a usable photo. Unfortunately the UIImagePickerController class does not have an option to restrict the user from using the front camera. Although you can check the size of the photo after the user is finished, it&#8217;s not great user experience to reject it after they go through the entire process of taking a photo.</p>
<p>One option is to replace the standard camera controls with a custom interface, but that&#8217;s a whole lot of work if you just want to prevent the user from taking a photo with the front camera. Fortunately there&#8217;s another option: put a transparent button over the &#8220;switch camera&#8221; button, which will intercept touch events and show an alert dialog. It sounds simple, but as you&#8217;ll see there are a few tricks to actually getting this to work.</p>
<p>We&#8217;re going to use UIImagePickerController&#8217;s <strong>cameraOverlayView</strong> property to add our button to the view hierarchy. We can&#8217;t simply provide a UIButton object though. In the latest iOS SDK, cameraOverlayView is automatically resized to fill the entire screen, while we only want to cover a small corner of it. Instead, we&#8217;re going to put the button inside a UIView subclass that will be used for layout and a few other tasks. Go ahead and create this UIView subclass in your project, call it <strong>ELCCameraOverlayView</strong>, and delete any methods the Xcode template includes by default.</p>
<p>We&#8217;ll need a button, so let&#8217;s start by giving our new subclass a UIButton instance variable named <strong>_button</strong> with a corresponding <strong>button</strong> property. Declare this as you&#8217;d declare any synthesized property, but let&#8217;s override the default setter method to also add it to the view hierarchy.</p>

<div class="wp_syntax"><table><tr><td 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>setButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>button;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> _button <span style="color: #002200;">!=</span> button <span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>_button removeFromSuperview<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>_button release<span style="color: #002200;">&#93;</span>;
        _button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>button retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> button <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&#41;</span>
        	<span style="color: #002200;">&#91;</span>self addSubview<span style="color: #002200;">:</span>button<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>You might create the button in another class (such as a view controller) and assign it to our custom class, but you can also create a standard button in your initWithFrame: method. Note that we still have to call <strong>addSubview:</strong> here as we&#8217;re not using the property accessor method (which is discouraged in init methods).</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>frame;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#40;</span> self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        _button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span> 240.0f, 0.0f, 80.0f, 80.0f <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>self addSubview<span style="color: #002200;">:</span>_button<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>With the button in place, let&#8217;s move on to intercepting touch events which would normally go to the &#8220;switch cameras&#8221; button. We can do this by overriding the UIView methods which are called to determine if an event occurred within a view&#8217;s frame or not. Just check to see if the event took place within the button&#8217;s frame rectangle.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>hitTest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>point withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>super hitTest<span style="color: #002200;">:</span>point withEvent<span style="color: #002200;">:</span>event<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> self.button <span style="color: #002200;">&#41;</span>
        <span style="color: #a61390;">return</span> self.button;
&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>pointInside<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>point withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> CGRectContainsPoint<span style="color: #002200;">&#40;</span> self.button.frame, point <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>It may seem like we&#8217;re almost done at this point. If you set the camera overlay view to an instance of this class you&#8217;ll see the &#8220;switch camera&#8221; button should no longer work, and if you give the button an action method you can pop up an alert message telling users not to use the front camera. However, if you rotate the phone to landscape mode, you&#8217;ll notice that while the &#8220;switch camera&#8221; button is re-positioned, our custom button is not! To see what I mean, try setting a custom background color on our button so you can see it on screen.</p>
<p>This is a tricky problem. Unlike UIViewController, our UIView subclass does not have any way of telling when the interface orientation is changed. This doesn&#8217;t even matter though, since UIImagePickerController doesn&#8217;t actually change its interface orientation, it simply re-arranges the camera buttons while remaining in UIInterfaceOrientationPortrait! </p>
<p>The way I&#8217;ve solved this problem is to use the accelerometer to determine the device orientation. It might sound complicated, but it&#8217;s actually not a lot of work. Start by adding a new instance variable <strong>_interfaceOrientation</strong> and property <strong>interfaceOrientation</strong> to your class, of type <strong>UIInterfaceOrientation</strong>. We&#8217;ll also override its setter method to call <strong>setNeedsLayout</strong> whenever its changed.</p>

<div class="wp_syntax"><table><tr><td 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>setInterfaceOrientation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> _interfaceOrientation <span style="color: #002200;">!=</span> interfaceOrientation <span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        _interfaceOrientation <span style="color: #002200;">=</span> interfaceOrientation;
        <span style="color: #002200;">&#91;</span>self setNeedsLayout<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Now let&#8217;s move the button whenever the orientation changes, and implement the required <strong>UIAccelerometerDelegate</strong> method.</p>

<div class="wp_syntax"><table><tr><td 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>layoutSubviews;
<span style="color: #002200;">&#123;</span>
    CGFloat width <span style="color: #002200;">=</span> CGRectGetWidth<span style="color: #002200;">&#40;</span> self.button.frame <span style="color: #002200;">&#41;</span>;
    CGFloat height <span style="color: #002200;">=</span> CGRectGetHeight<span style="color: #002200;">&#40;</span> self.button.frame <span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span> self.interfaceOrientation <span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">case</span> UIInterfaceOrientationPortrait<span style="color: #002200;">:</span>
        <span style="color: #a61390;">case</span> UIInterfaceOrientationPortraitUpsideDown<span style="color: #002200;">:</span>
            self.button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span> CGRectGetMaxX<span style="color: #002200;">&#40;</span> self.bounds <span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> width, 0.0f, width, height <span style="color: #002200;">&#41;</span>;
            <span style="color: #a61390;">break</span>;
        <span style="color: #a61390;">case</span> UIInterfaceOrientationLandscapeRight<span style="color: #002200;">:</span>
            self.button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span> CGRectGetMaxX<span style="color: #002200;">&#40;</span> self.bounds <span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> width, CGRectGetMaxY<span style="color: #002200;">&#40;</span> self.bounds <span style="color: #002200;">&#41;</span> <span style="color: #002200;">-</span> height <span style="color: #002200;">-</span> 50.0f, width, height <span style="color: #002200;">&#41;</span>;
            <span style="color: #a61390;">break</span>;
        <span style="color: #a61390;">case</span> UIInterfaceOrientationLandscapeLeft<span style="color: #002200;">:</span>
            self.button.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span> 0.0f, 0.0f, width, height <span style="color: #002200;">&#41;</span>;
            <span style="color: #a61390;">break</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;">void</span><span style="color: #002200;">&#41;</span>accelerometer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIAccelerometer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>accelerometer didAccelerate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIAcceleration <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>acceleration;
<span style="color: #002200;">&#123;</span> 
	CGFloat x <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #002200;">&#91;</span>acceleration x<span style="color: #002200;">&#93;</span>; 
	CGFloat y <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>acceleration y<span style="color: #002200;">&#93;</span>; 
	CGFloat angle <span style="color: #002200;">=</span> <span style="color: #a61390;">atan2</span><span style="color: #002200;">&#40;</span>y, x<span style="color: #002200;">&#41;</span>; 
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> angle &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span>2.25f <span style="color: #002200;">&amp;&amp;</span> angle &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span>0.25f <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
        self.interfaceOrientation <span style="color: #002200;">=</span> UIInterfaceOrientationPortrait;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> angle &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span>1.75f <span style="color: #002200;">&amp;&amp;</span> angle &lt;<span style="color: #002200;">=</span> 0.75f <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
        self.interfaceOrientation <span style="color: #002200;">=</span> UIInterfaceOrientationLandscapeRight;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span> angle &gt;<span style="color: #002200;">=</span> 0.75f <span style="color: #002200;">&amp;&amp;</span> angle &lt;<span style="color: #002200;">=</span> 2.25f <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
        self.interfaceOrientation <span style="color: #002200;">=</span> UIInterfaceOrientationPortraitUpsideDown;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> angle &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span>2.25f || angle &gt;<span style="color: #002200;">=</span> 2.25f <span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
        self.interfaceOrientation <span style="color: #002200;">=</span> UIInterfaceOrientationLandscapeLeft;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>We&#8217;re almost done! Just make sure to start and stop the accelerometer in your init and dealloc methods.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>frame;
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#40;</span> self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        _interfaceOrientation <span style="color: #002200;">=</span> UIInterfaceOrientationPortrait;
        _button <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIButton alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span> 240.0f, 0.0f, 80.0f, 80.0f <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAccelerometer sharedAccelerometer<span style="color: #002200;">&#93;</span> setDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>self addSubview<span style="color: #002200;">:</span>_button<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> self;
<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>dealloc;
<span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAccelerometer sharedAccelerometer<span style="color: #002200;">&#93;</span> setDelegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_button release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Finished! If you haven&#8217;t tested your overlay yet, you can add it to your UIImagePickerController as so.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">UIImagePickerController <span style="color: #002200;">*</span>controller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImagePickerController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
ELCCameraOverlayView <span style="color: #002200;">*</span>view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ELCCameraOverlayView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>controller.view.frame<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>view.button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>selectFrontCamera<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;
&nbsp;
controller.sourceType <span style="color: #002200;">=</span> UIImagePickerControllerSourceTypeCamera;
controller.cameraCaptureMode <span style="color: #002200;">=</span> UIImagePickerControllerCameraCaptureModePhoto;
controller.cameraDevice <span style="color: #002200;">=</span> UIImagePickerControllerCameraDeviceRear;
controller.delegate <span style="color: #002200;">=</span> self;
controller.cameraOverlayView <span style="color: #002200;">=</span> view;
&nbsp;
<span style="color: #002200;">&#91;</span>self.navigationController presentModalViewController<span style="color: #002200;">:</span>controller animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>controller release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>view release<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Don&#8217;t forget to provide the button&#8217;s action method. You could show an alert, for instance.</p>

<div class="wp_syntax"><table><tr><td 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>selectFrontCamera<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: #400080;">NSString</span> <span style="color: #002200;">*</span>title <span style="color: #002200;">=</span> NSLocalizedString<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Front Camera Disabled&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span> <span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>message <span style="color: #002200;">=</span> NSLocalizedString<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;The front camera does not have sufficient resolution.&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span> <span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>button <span style="color: #002200;">=</span> NSLocalizedString<span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Okay&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span> <span style="color: #002200;">&#41;</span>;
    UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span>title message<span style="color: #002200;">:</span>message delegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> cancelButtonTitle<span style="color: #002200;">:</span>button otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;ve uploaded the <a href="https://gist.github.com/1166388">complete ELCCameraOverlayView class files here</a>. Leave a comment if you have any questions!</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2011/08/23/disable-the-iphones-front-camera/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
