<?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>[iPhoneiOS dev:tips]; &#187; John Muchow</title>
	<atom:link href="http://iPhoneDeveloperTips.com/author/admin/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com</link>
	<description>Tips and Tricks for iPhone developers</description>
	<lastBuildDate>Thu, 29 Jul 2010 17:59:45 +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>Capture iPhone Simulator Screenshots &#8211; Revisited &#8211; iPhone Simulator Cropper</title>
		<link>http://iPhoneDeveloperTips.com/tools/capture-screenshots-of-the-iphone-simulator-with-iphone-simulator-cropper.html</link>
		<comments>http://iPhoneDeveloperTips.com/tools/capture-screenshots-of-the-iphone-simulator-with-iphone-simulator-cropper.html#comments</comments>
		<pubDate>Wed, 28 Jul 2010 07:04:13 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6775</guid>
		<description><![CDATA[A colleague on a recent iPhone project was looking for a tool to capture a series of screenshots for an upcoming application demo. In a Google search he first bumped into a post I wrote back in February of 2009: Capture iPhone Simulator Screenshots – Open Source Screen Capture Tool, a nice Mac tool for [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague on a recent iPhone project was looking for a tool to capture a series of screenshots for an upcoming application demo. In a Google search he first bumped into a post I wrote back in February of 2009: <a href="http://iphonedevelopertips.com/general/open-source-screen-capture-tool.html">Capture iPhone Simulator Screenshots – Open Source Screen Capture Tool</a>, a nice Mac tool for taking screenshots. As luck would have it, he also found another screen capture tool, one focused solely on iPhone screenshots: <a  target="_blank"   href="http://www.curioustimes.de/iphonesimulatorcropper/">iPhone-Simulator Cropper</a>.</p>
<h5>iPhone-Simulator Cropper</h5>
<p>This tool works by capturing the screen of the simulator runnning on your system. One really slick feature is the option to create captured images in two primary formats &#8211; first, a format suitable for upload to iTunes for your application screenshots &#8211; second, capturing a screenshot that is suitable for display on a website.</p>
<p>The following images show the iPhone-Simulator Cropper application, as well as two sample images captured:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/cropper0.jpg" /></p>
<p>iTunes Connect / App Store:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/cropper1.jpg" /></p>
<p>Website (iPhone Device from Apple Marketing):</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/cropper2.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/tools/capture-screenshots-of-the-iphone-simulator-with-iphone-simulator-cropper.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Truncate a String and Append an Ellipsis, Respecting the Font Size</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/truncate-an-nsstring-and-append-an-ellipsis-respecting-the-font-size.html</link>
		<comments>http://iPhoneDeveloperTips.com/cocoa/truncate-an-nsstring-and-append-an-ellipsis-respecting-the-font-size.html#comments</comments>
		<pubDate>Mon, 26 Jul 2010 11:52:06 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6737</guid>
		<description><![CDATA[A number of the UI related controls will automatically truncate and append ellipsis with no effort required on your part. For example, with UILabel you can specify the linebreak mode to indicate how you would like the system to manage wrapping and truncating the label text. However, they are times when having a method to [...]]]></description>
			<content:encoded><![CDATA[<p>A number of the UI related controls will automatically truncate and append ellipsis with no effort required on your part. For example, with UILabel you can specify the linebreak mode to indicate how you would like the system to manage wrapping and truncating the label text.</p>
<p>However, they are times when having a method to truncate a string without using a UI control would be handy. In this post I&#8217;ll create a category which will add a method to the  <strong>NSString</strong> class to do just that. You can read more about working with categories in this post: <a  target="_blank"  href="http://iphonedevelopertips.com/objective-c/categories.html">Introduction to Categories</a>.</p>
<h5>NSString Category</h5>
<p>Start by creating a new interface file with the name: <strong>NSString+TruncateToWidth.h</strong> &#8211; appending the method name to the class is a common naming convention when working with categories.</p>
<p>The code below defines a method that will be available to all <strong>NSString</strong> objects. The method will truncate a string to a specific width, using the font size to properly determine the string size before truncating:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">&#40;</span>TruncateToWidth<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>stringByTruncatingToWidth<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGFloat<span style="color: #002200;">&#41;</span>width withFont<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIFont <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>font;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<h5>Code to Truncate NSString</h5>
<p>The implementation of the <strong>stringByTruncatingToWidth</strong> method follows, add this code to the <strong>NSString+TruncateToWidth.m</strong> file.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;NSString+TruncateToWidth.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#define ellipsis @&quot;…&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">&#40;</span>TruncateToWidth<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>stringByTruncatingToWidth<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGFloat<span style="color: #002200;">&#41;</span>width withFont<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIFont <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>font
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Create copy that will be the returned result</span>
  <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>truncatedString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self mutableCopy<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Make sure string is longer than requested width</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self sizeWithFont<span style="color: #002200;">:</span>font<span style="color: #002200;">&#93;</span>.width &gt; width<span style="color: #002200;">&#41;</span>
  <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Accommodate for ellipsis we'll tack on the end</span>
    width <span style="color: #002200;">-=</span> <span style="color: #002200;">&#91;</span>ellipsis sizeWithFont<span style="color: #002200;">:</span>font<span style="color: #002200;">&#93;</span>.width;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Get range for last character in string</span>
    <span style="color: #a61390;">NSRange</span> range <span style="color: #002200;">=</span> <span style="color: #002200;">&#123;</span>truncatedString.length <span style="color: #002200;">-</span> <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">1</span><span style="color: #002200;">&#125;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Loop, deleting characters until string fits within width</span>
    <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>truncatedString sizeWithFont<span style="color: #002200;">:</span>font<span style="color: #002200;">&#93;</span>.width &gt; width<span style="color: #002200;">&#41;</span> 
    <span style="color: #002200;">&#123;</span>
      <span style="color: #11740a; font-style: italic;">// Delete character at end</span>
      <span style="color: #002200;">&#91;</span>truncatedString deleteCharactersInRange<span style="color: #002200;">:</span>range<span style="color: #002200;">&#93;</span>;
&nbsp;
      <span style="color: #11740a; font-style: italic;">// Move back another character</span>
      range.location<span style="color: #002200;">--</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Append ellipsis</span>
    <span style="color: #002200;">&#91;</span>truncatedString replaceCharactersInRange<span style="color: #002200;">:</span>range withString<span style="color: #002200;">:</span>ellipsis<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #a61390;">return</span> truncatedString;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Notice that the desired final width of the string is passed in, as well as the font that will be used when calculating the size (width) of the string. The process is quite simple: change the incoming width to accommodate an ellipsis on the end of the string &#8211; loop through the string removing characters from the end until the desired width is reached &#8211; append an ellipsis onto the string.</p>
<h5>Calling the Truncate NSString Method</h5>
<p>You can now call the method <strong>stringByTruncatingToWidth:withFont:</strong> on any NSString object:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>str <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Lorem ipsum dolor sit amet, consectetuer adipiscing&quot;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Adjust the width parameter to change the final string width</span>
str <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>str stringByTruncatingToWidth<span style="color: #002200;">:</span><span style="color: #2400d9;">170</span> withFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">15</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, str<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>The output from above would look as follows:</p>
<p><strong>Lorem ipsum dolor sit…</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/cocoa/truncate-an-nsstring-and-append-an-ellipsis-respecting-the-font-size.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Download and Install Older Versions of Xcode (Xcode Previous Releases)</title>
		<link>http://iPhoneDeveloperTips.com/xcode/download-and-install-older-versions-of-xcode-xcode-previous-releases.html</link>
		<comments>http://iPhoneDeveloperTips.com/xcode/download-and-install-older-versions-of-xcode-xcode-previous-releases.html#comments</comments>
		<pubDate>Fri, 23 Jul 2010 01:02:07 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6710</guid>
		<description><![CDATA[As a general rule of thumb, it&#8217;s best to stick with the latest release of Xcode. That said, there are times when running an older release can be a good thing. You can download older versions of Xcode by logging into Apple Developer Connection &#8211; Downloads and ADC Program Assests (http://connect.apple.com) &#8211; You will need [...]]]></description>
			<content:encoded><![CDATA[<p>As a general rule of thumb, it&#8217;s best to stick with the latest release of Xcode. That said, there are times when running an older release can be a good thing. </p>
<p>You can download older versions of Xcode by logging into <a href="http://connect.apple.com">Apple Developer Connection &#8211; Downloads and ADC Program Assests</a> (<a href="http://connect.apple.com">http://connect.apple.com</a>) &#8211; You will need to be a member of the developer program to login.</p>
<p>Once on the site, from the <strong>Downloads</strong> section, choose <strong>Developer Tools</strong> &#8211; you will be shown with a list of all Xcode versions, back to 1.0 released in October of 2004.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/xcode/download-and-install-older-versions-of-xcode-xcode-previous-releases.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Play Movies from the Application Bundle or from a Remote Server (URL)</title>
		<link>http://iPhoneDeveloperTips.com/video/how-to-play-movies-from-application-bundle-or-from-a-remote-server-url.html</link>
		<comments>http://iPhoneDeveloperTips.com/video/how-to-play-movies-from-application-bundle-or-from-a-remote-server-url.html#comments</comments>
		<pubDate>Wed, 21 Jul 2010 00:51:45 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6691</guid>
		<description><![CDATA[In the previous two posts I wrote about how to create a movie player that would work across OS versions, as well as how to play a movie in portrait mode (on 3.2 and above) : Display iPhone Movies in Portrait Mode and Getting MPMoviePlayerController to Cooperate with iOS4, 3.2 (iPad) and Earlier Versions of [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous two posts I wrote about how to create a movie player that would work across OS versions, as well as how to play a movie in portrait mode (on 3.2 and above) : <a href="http://iphonedevelopertips.com/video/display-iphone-movies-in-portrait-mode-updated.html">Display iPhone Movies in Portrait Mode</a> and <a  target="_blank"  href="http://iphonedevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html">Getting MPMoviePlayerController to Cooperate with iOS4, 3.2 (iPad) and Earlier Versions of iPhone SDK</a> </p>
<p>For both posts, in order to create a working example that one could download and run as is, the code examples referenced a movie that I included in the application bundle. Although handy, this prompted a number of questions about how to play a movie from a remote resource.</p>
<p>I&#8217;ve updated the original examples for both posts, with an option to play movies from the application bundle or from a remote server.<br />
<span id="more-6691"></span></p>
<h5>Play Movie from Server</h5>
<p>The first change I made was in <strong>CustomMoviePlayerViewController.m</strong>, where I added a method to initialize the movie player with a NSURL object:</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;">id</span><span style="color: #002200;">&#41;</span>initWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>URL
<span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
  <span style="color: #002200;">&#123;</span>
    movieURL <span style="color: #002200;">=</span> URL;
    <span style="color: #002200;">&#91;</span>movieURL retain<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #002200;">&#125;</span>
  <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;">id</span><span style="color: #002200;">&#41;</span>initWithPath<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>moviePath
<span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
  <span style="color: #002200;">&#123;</span>
    movieURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> fileURLWithPath<span style="color: #002200;">:</span>moviePath<span style="color: #002200;">&#93;</span>;    
    <span style="color: #002200;">&#91;</span>movieURL retain<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
  <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>For both methods, the end result is an initialized NSURL object.</p>
<p>The other code change is in <strong>TestViewController.m</strong> where I updated the <strong>loadMoviePlayer</strong> method to support calling either of the above methods:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><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>loadMoviePlayer
<span style="color: #002200;">&#123;</span>  
<span style="color: #11740a; font-style: italic;">/*
  // Play movie from app bundle
  NSString *path = [[NSBundle mainBundle] pathForResource:@&quot;Movie-1&quot; ofType:@&quot;mp4&quot; inDirectory:nil];
  moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];
*/</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Play movie from URL</span>
  <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>movieURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://someurlsomewhere.com/movie.mp4&quot;</span><span style="color: #002200;">&#93;</span>;
  moviePlayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CustomMoviePlayerViewController alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Show the movie player as modal</span>
  <span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>moviePlayer animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Prep and play the movie</span>
  <span style="color: #002200;">&#91;</span>moviePlayer readyPlayer<span style="color: #002200;">&#93;</span>;    
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Comment in/out the relevant code in lines 4 &#8211; 11 to swap between playing from a file in the bundle and a movie accessible on a remote server.</p>
<h5>Download Movie Player Source Code</h5>
<p><a href="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/MoviePlayer-ios4-Landscape.zip">MoviePlayer in Landscape Mode</a></p>
<p><a href="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/MoviePlayer-ios4-Portrait.zip">MoviePlayer in Portrait Mode (requires 3.2 OS and greater)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/video/how-to-play-movies-from-application-bundle-or-from-a-remote-server-url.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Display iPhone Movies in Portrait Mode (Updated)</title>
		<link>http://iPhoneDeveloperTips.com/video/display-iphone-movies-in-portrait-mode-updated.html</link>
		<comments>http://iPhoneDeveloperTips.com/video/display-iphone-movies-in-portrait-mode-updated.html#comments</comments>
		<pubDate>Wed, 14 Jul 2010 00:36:36 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6652</guid>
		<description><![CDATA[In the previous post, Getting MPMoviePlayerController to Cooperate with iOS4 and Earlier Versions of iPhone SDK, I demonstrated how to work with the most recent changes in iPhone OS 3.2 and 4.0 MPMoviePlayerController to enable one application to play movies regardless of the OS version on the device. In this post I want to show [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post, <a  target="_blank"  href="http://iphonedevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html">Getting MPMoviePlayerController to Cooperate with iOS4 and Earlier Versions of iPhone SDK</a>, I demonstrated how to work with the most recent changes in iPhone OS 3.2 and 4.0 <strong>MPMoviePlayerController</strong> to enable one application to play movies regardless of the OS version on the device.</p>
<p>In this post I want to show you a few minor changes you can make to the previous app to display a movie in portrait mode, something that was not possible in earlier (pre 3.2) OS versions. With that said, back in January of 2010 I did cover a means to create the illusion that a movie was in portrait mode, if this piques your interest, have a look here: <a  target="_blank"  href="http://iphonedevelopertips.com/video/play-movies-in-portrait-mode-with-mpmovieplayercontroller-using-public-apis.html">Play iPhone Movies in Portrait Mode with MPMoviePlayerController using Public API’s</a><br />
<span id="more-6652"></span></p>
<p>The figure below shows the same movie as played back in landscape and portrait:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/portraitMode.png" /></p>
<h5>Play Movies in Portrait Mode</h5>
<p>The code below is from the previous post and shows how to configure the movie player view to display in landscape:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MPMoviePlayerController <span style="color: #002200;">*</span>mp <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MPMoviePlayerController alloc<span style="color: #002200;">&#93;</span>
     initWithContentURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span>;
&nbsp;
...
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> moviePlayerLoadStateChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  ...
  <span style="color: #11740a; font-style: italic;">// Rotate the view for landscape playback</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setBounds<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">480</span>, <span style="color: #2400d9;">320</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">240</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setTransform<span style="color: #002200;">:</span>CGAffineTransformMakeRotation<span style="color: #002200;">&#40;</span>M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>; 
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Set frame of movieplayer</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mp view<span style="color: #002200;">&#93;</span> setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">480</span>, <span style="color: #2400d9;">320</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  ...
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>To playback a movie in portrait mode is as easy as removing the code for the rotation and changing the frame of the movieplayer. I&#8217;ve also added a call to scale the movie so it fills the screen, this will maintain the aspect ratio.</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> moviePlayerLoadStateChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  ...
  <span style="color: #11740a; font-style: italic;">// Rotate the view for landscape playback</span>
  <span style="color: #11740a; font-style: italic;">//	  [[self view] setBounds:CGRectMake(0, 0, 480, 320)];</span>
  <span style="color: #11740a; font-style: italic;">//		[[self view] setCenter:CGPointMake(160, 240)];</span>
  <span style="color: #11740a; font-style: italic;">//		[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; </span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Set frame of movieplayer</span>
  <span style="color: #11740a; font-style: italic;">// [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mp view<span style="color: #002200;">&#93;</span> setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">320</span>, <span style="color: #2400d9;">160</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Scale uniformly, maintaining aspect ratio</span>
  <span style="color: #002200;">&#91;</span>mp setScalingMode<span style="color: #002200;">:</span>MPMovieScalingModeAspectFill<span style="color: #002200;">&#93;</span>;
&nbsp;
  ...
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This approach works on 3.2 (iPad) as well as 4.0 and greater. Needless to say, given the large display on the iPad this is a nice alternative as the user can watch videos without rotating the device.</p>
<h5>Source Code</h5>
<p><a href="http://iphonedevelopertips.com/wp-content/uploads/2010/07/MoviePlayer-Portrait-Mode-ios4.zip">Download the source code</a> to build an iPhone app that displays movies in portrait mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/video/display-iphone-movies-in-portrait-mode-updated.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting MPMoviePlayerController to Work with iOS4, 3.2 (iPad) and Earlier Versions of iPhone SDK</title>
		<link>http://iPhoneDeveloperTips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html</link>
		<comments>http://iPhoneDeveloperTips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html#comments</comments>
		<pubDate>Fri, 09 Jul 2010 02:52:29 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6579</guid>
		<description><![CDATA[The API and overall approach for working with MPMoviePlayerController has changed just enough in the 3.2 SDK (iPad) and iOS4 SDK to cause working applications in earlier releases to be problematic when running on later SDKs. In this post I&#8217;ll walk through a short example of a movie player application that will work with 3.x, [...]]]></description>
			<content:encoded><![CDATA[<p>The API and overall approach for working with <strong>MPMoviePlayerController</strong> has changed just enough in the  3.2 SDK (iPad) and iOS4 SDK to cause working applications in earlier releases to be problematic when running on later SDKs. In this post I&#8217;ll walk through a short example of a movie player application that will work with 3.x, 3.2 and 4.0 SDKs. </p>
<p>In the next post, <a href="http://iphonedevelopertips.com/video/display-iphone-movies-in-portrait-mode-updated.html">Display iPhone Movies in Portrait Mode</a>, I&#8217;ll show how to create a movie player that runs in a view that is <em>not</em> fullscreen as well as how to show a few lines of code to display a movie in portrait mode &#8211; the one caveat here is that both of the tips in the second post will apply only to OS versions 3.2 and up.<br />
<span id="more-6579"></span></p>
<h5>What&#8217;s Changed with MPMoviePlayerController in 3.2 and 4.0?</h5>
<p>There are any number of changes in the <strong>MPMoviePlayerController</strong>, however, a few standout as potential roadblocks to getting a movie to display:</p>
<p>- In 3.1 and earlier versions, <strong>MPMoviePlayerController</strong> was full-screen only. Playing a movie was straight-forward, create a player, initialize with a file (path or URL) and call a method to start playback &#8211; the rest was taken care of for you.</p>
<p>- With 3.2 and later, movies can playback in fullscreen or a custom view, as well as portrait or landscape.</p>
<p>- The notification <strong>MPMoviePlayerContentPreloadDidFinishNotification</strong>  has been deprecated. This notification was used in earlier versions to notify observers that a movie was loaded and ready to play.</p>
<h5>The Movie Application</h5>
<p>The application in this post is quite simple, it consists of a view controller with nothing more than a button to start playback and a second view controller to manage a <strong>MPMoviePlayerController</strong> and the <strong>NSURL</strong> of the movie. The two views are shown in the figures below:</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/movie1.png" /></p>
<h5>Primary View Controller</h5>
<p>The interface definition for the primary view is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@class</span> CustomMoviePlayerViewController;
&nbsp;
<span style="color: #a61390;">@interface</span> TestViewController <span style="color: #002200;">:</span> UIViewController
<span style="color: #002200;">&#123;</span>
  CustomMoviePlayerViewController  <span style="color: #002200;">*</span>moviePlayer;
  UIButton  <span style="color: #002200;">*</span>playButton;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p><strong>CustomMoviePlayerViewController</strong> is the controller for managing the movie, we&#8217;ll look at that code in a moment. </p>
<p>In the code below we create the view, add a play button, create a method for processing a button press event and within <strong>loadMoviePlayer</strong>, we get a reference to the movie file and create an instance of the <strong>CustomMoviePlayerViewController</strong>, which will load and play the movie.</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>loadView
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Setup the view</span>
  <span style="color: #002200;">&#91;</span>self setView<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> applicationFrame<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setBackgroundColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor grayColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setUserInteractionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Add play button </span>
  playButton <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><span style="color: #2400d9;">53</span>, <span style="color: #2400d9;">212</span>, <span style="color: #2400d9;">214</span>, <span style="color: #2400d9;">36</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;    
  <span style="color: #002200;">&#91;</span>playButton setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;playButton.png&quot;</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>playButton 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>buttonPressed<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span> UIControlEventTouchUpInside<span style="color: #002200;">&#93;</span>;    
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span>playButton<span style="color: #002200;">&#93;</span>;  
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>buttonPressed<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: #11740a; font-style: italic;">// If pressed, play movie</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>button <span style="color: #002200;">==</span> playButton<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#91;</span>self loadMoviePlayer<span style="color: #002200;">&#93;</span>;	
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadMoviePlayer
<span style="color: #002200;">&#123;</span>  
  <span style="color: #11740a; font-style: italic;">// Play movie from the bundle</span>
  <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>path <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> pathForResource<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Movie-1&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;mp4&quot;</span> inDirectory<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Create custom movie player   </span>
  moviePlayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CustomMoviePlayerViewController alloc<span style="color: #002200;">&#93;</span> initWithPath<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Show the movie player as modal</span>
  <span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>moviePlayer animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Prep and play the movie</span>
  <span style="color: #002200;">&#91;</span>moviePlayer readyPlayer<span style="color: #002200;">&#93;</span>;    
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Notice that the movie for this example is loaded from the application bundle. Also, once the custom movie player is created, the view is shown as a modal view.</p>
<h5>Custom Movie Player View Controller</h5>
<p>The interface definition for the movie view controller is below:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> CustomMoviePlayerViewController <span style="color: #002200;">:</span> UIViewController 
<span style="color: #002200;">&#123;</span>
  MPMoviePlayerController <span style="color: #002200;">*</span>mp;
  <span style="color: #400080;">NSURL</span>  <span style="color: #002200;">*</span>movieURL;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithPath<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>moviePath;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>readyPlayer;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>The initialization code is where the movie player and associated URL are created. The primary goal of the initialization is to create the <strong>NSURL</strong> needed by the movie player.</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;">id</span><span style="color: #002200;">&#41;</span>initWithPath<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>moviePath
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Initialize and create movie URL</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
  <span style="color: #002200;">&#123;</span>
    movieURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> fileURLWithPath<span style="color: #002200;">:</span>moviePath<span style="color: #002200;">&#93;</span>;    
    <span style="color: #002200;">&#91;</span>movieURL retain<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
  <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The code to create the player and setup the notifications is where we start to deal with the differences in how the movie player works on various OS versions. Notice below the call to <strong>respondsToSelector</strong>, this is the Apple recommended way to check for feature availability, versus looking for a specific OS version. </p>
<p>For devices running 3.2 and above, the movie player controller has a method named <strong>loadstate</strong>, if this exists we can access a few additional methods to set the player to fullscreen as well as request the movie to begin preloading.  </p>
<p>Equally important is the distinction of which notification to setup &#8211; see lines 16 and 24.</p>
<p>You can read more about managing different OS version in this post <a  target="_blank"  href="http://iphonedevelopertips.com/xcode/base-sdk-and-iphone-os-deployment-target-developing-apps-with-the-4-x-sdk-deploying-to-3-x-devices.html">Developing iPhone Apps with iOS4 SDK, Deploying to 3.x Devices</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><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> readyPlayer
<span style="color: #002200;">&#123;</span>
   mp <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MPMoviePlayerController alloc<span style="color: #002200;">&#93;</span> initWithContentURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// For 3.2 devices and above</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mp respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>loadState<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
  <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Set movie player layout</span>
    <span style="color: #002200;">&#91;</span>mp setControlStyle<span style="color: #002200;">:</span>MPMovieControlStyleFullscreen<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>mp setFullscreen<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// May help to reduce latency</span>
    <span style="color: #002200;">&#91;</span>mp prepareToPlay<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Register that the load state changed (movie is ready)</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
        selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePlayerLoadStateChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
        name<span style="color: #002200;">:</span>MPMoviePlayerLoadStateDidChangeNotification 
        object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>  
  <span style="color: #a61390;">else</span>
  <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Register to receive a notification when the movie is in memory and ready to play.</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
        selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePreloadDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
        name<span style="color: #002200;">:</span>MPMoviePlayerContentPreloadDidFinishNotification 
        object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Register to receive a notification when the movie has finished playing. </span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
        selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePlayBackDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
        name<span style="color: #002200;">:</span>MPMoviePlayerPlaybackDidFinishNotification 
        object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The next two chunks of code are for each of the selectors, one for each notification. The code below is for earlier OS versions &#8211; nothing more than removing the notification and asking the movie to play.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/*---------------------------------------------------------------------------
* For 3.1.x devices
* For 3.2 and 4.x see moviePlayerLoadStateChanged: 
*--------------------------------------------------------------------------*/</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> moviePreloadDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Remove observer</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> 	defaultCenter<span style="color: #002200;">&#93;</span> 
    removeObserver<span style="color: #002200;">:</span>self
    name<span style="color: #002200;">:</span>MPMoviePlayerContentPreloadDidFinishNotification
    object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// Play the movie</span>
   <span style="color: #002200;">&#91;</span>mp play<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>For the notification generated in 3.2 and above, there are a few more details to tend to:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/*---------------------------------------------------------------------------
* For 3.2 and 4.x devices
* For 3.1.x devices see moviePreloadDidFinish:
*--------------------------------------------------------------------------*/</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> moviePlayerLoadStateChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Unless state is unknown, start playback</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mp loadState<span style="color: #002200;">&#93;</span> <span style="color: #002200;">!=</span> MPMovieLoadStateUnknown<span style="color: #002200;">&#41;</span>
  <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Remove observer</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> 
      removeObserver<span style="color: #002200;">:</span>self
      name<span style="color: #002200;">:</span>MPMoviePlayerLoadStateDidChangeNotification 
      object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// When tapping movie, status bar will appear, it shows up</span>
    <span style="color: #11740a; font-style: italic;">// in portrait mode by default. Set orientation to landscape</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> setStatusBarOrientation<span style="color: #002200;">:</span>UIInterfaceOrientationLandscapeRight animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Rotate the view for landscape playback</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setBounds<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">480</span>, <span style="color: #2400d9;">320</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">240</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> setTransform<span style="color: #002200;">:</span>CGAffineTransformMakeRotation<span style="color: #002200;">&#40;</span>M_PI <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>; 
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Set frame of movie player</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>mp view<span style="color: #002200;">&#93;</span> setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">480</span>, <span style="color: #2400d9;">320</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Add movie player as subview</span>
    <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self view<span style="color: #002200;">&#93;</span> addSubview<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>mp view<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;   
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Play the movie</span>
    <span style="color: #002200;">&#91;</span>mp play<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Beyond removing the notification, we also adjust the status bar, rotate the view, set the frame of the movie player, add the movie player as a subview in the view controller and wrap it all up by asking the movie to play.</p>
<p><strong>Note:</strong> MPMoviePlayerViewController is also an option over creating your own view controller as I&#8217;ve done here.</p>
<h5>Source Code</h5>
<p>The easiest way to see all this working is to <a href="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/MoviePlayer-ios4.zip">download the source code</a> and step through the code in the debugger.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Developing iPhone Apps with iOS4 SDK, Deploying to 3.x Devices : Base SDK and iPhone OS Deployment Target</title>
		<link>http://iPhoneDeveloperTips.com/xcode/base-sdk-and-iphone-os-deployment-target-developing-apps-with-the-4-x-sdk-deploying-to-3-x-devices.html</link>
		<comments>http://iPhoneDeveloperTips.com/xcode/base-sdk-and-iphone-os-deployment-target-developing-apps-with-the-4-x-sdk-deploying-to-3-x-devices.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 07:08:23 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6506</guid>
		<description><![CDATA[Editor&#8217;s Note:You can download and install any previous release of Xcode if you would like to roll back to an earlier version. You can get the specifics here: Download and Install Older Versions of Xcode. If you&#8217;ve installed Xcode 3.2.3 you quickly became aware that the only SDK&#8217;s packaged with this version are 4.0 and [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Editor&#8217;s Note:</strong>You can download and install any previous release of Xcode if you would like to roll back to an earlier version. You can get the specifics here: <a  target="_blank"  href="http://iphonedevelopertips.com/xcode/download-and-install-older-versions-of-xcode-xcode-previous-releases.html">Download and Install Older Versions of Xcode</a>.<br />
</em><br />
If you&#8217;ve installed Xcode 3.2.3 you quickly became aware that the only SDK&#8217;s packaged with this version are 4.0 and 3.2. Until 4.x has widespread adoption, chances are you&#8217;ll want your applications to run on earlier versions of the iPhone OS (iOS) SDK. You can accomplish this feat through two configuration options within Xcode, the Base SDK and the iPhone OS Deployment Target.<br />
<span id="more-6506"></span></p>
<h5>Base SDK</h5>
<p>The Base SDK is the version of SDK that will be used when compiling your application &#8211; the compiler will use the headers and libraries of this specific SDK. For example, in the image below notice that there are only two choices for the Base SDK for both the device and simulator, versions 3.2 and 4.0.</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/basesdk.png" /></p>
<p>However, we have an issue here, if you build an application with the latest SDK and deploy on a device with an earlier OS, chances are your application will crash if you reference any code in a 4.x API while running the application on a 3.x device. Also, the 3.2 SDK is for the iPad only, so this isn&#8217;t an option when deploying to an iPhone or iPod touch.</p>
<h5>iPhone OS Deployment Target</h5>
<p>To specify which OS version is the minimum that your application will support, you set the deployment target. Your application will then run on this minimum OS as well as all later versions.</p>
<p><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/07/targetsdk.png" /></p>
<p>This is all well and good, however, the obvious question is how to deploy on an earlier OS version yet take advantage of features for those devices that are running a later OS?</p>
<h5>Check for Feature Availability Not OS Version</h5>
<p>When targeting an earlier OS as mentioned above, yet you want to take advantage of features of a later OS for devices that support it, you can use the method <strong>respondsToSelector</strong> to check if the receiver  implements or inherits a method that can respond to a specified message. This approach follows Apple&#8217;s recommendation to check for availability of features versus a specific OS version.</p>
<p>In the example below the code will check if the object returned by <strong>[UIDevice currentDevice]</strong> will respond to the selector shown, if so, you can write relevant multi-tasking code:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIDevice currentDevice<span style="color: #002200;">&#93;</span> respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>isMultitaskingSupported<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Multi-tasking code for supported devices</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">else</span>
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Devices without multi-tasking support</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Another time when that you may choose to use <strong>respondsToSelector</strong> is for cases when the implementation of the same API has changed with a later OS version. I ran into this particular case when writing code for displaying movies using the <strong>MPMoviePlayerController</strong>. In the 4.x SDK the notifications have changed slightly &#8211; in 2.0 to 3.1 <strong>MPMoviePlayerContentPreloadDidFinishNotification</strong> was the notification you would use to receive notice that a movie was ready to play. With 3.2 (iPad) and later, <strong>MPMoviePlayerContentPreloadDidFinishNotification</strong> has been deprecated and  <strong>MPMoviePlayerLoadStateDidChangeNotification</strong> has taken its place. </p>
<p>The code example below shows how you may go about using <strong>respondsToSelector</strong> to figure out which notification you should request based on the whether or not the movie player can return information about its load state:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MPMoviePlayerController <span style="color: #002200;">*</span>mp <span style="color: #002200;">=</span> 
   <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MPMoviePlayerController alloc<span style="color: #002200;">&#93;</span> initWithContentURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// This method is available on 3.2 and greater...</span>
 <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mp respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>loadState<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Register to receive notification when load state changed</span>
  <span style="color: #11740a; font-style: italic;">// (check for playable, stalled...)</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
                       selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePlayerLoadStateChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
                       name<span style="color: #002200;">:</span>MPMoviePlayerLoadStateDidChangeNotification 
                       object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">else</span>
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// Register to receive a notification when the movie is ready to play.</span>
  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
                         selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePreloadDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
                         name<span style="color: #002200;">:</span>MPMoviePlayerContentPreloadDidFinishNotification 
                         object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>Check for Function Availability</h5>
<p>Beyond working with objects, if you need to check for the availability of a specific function, you do so by comparing the function to NULL. In the example below I check for a function related to creating a PDF-based graphics context (available in 3.2 and later).</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>UIGraphicsBeginPDFContextToFile <span style="color: #002200;">!=</span> <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">// The function is available</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<h5>Testing Across OS Versions</h5>
<p>Unfortunately, with the upgrade to the latest Xcode (3.2.3) there are no simulators for 3.1.x and earlier OS versions. Although it has always been recommended to test your apps on device, at this point it becomes a necessity. </p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/xcode/base-sdk-and-iphone-os-deployment-target-developing-apps-with-the-4-x-sdk-deploying-to-3-x-devices.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Pragmatic Studio iPhone/iPad Developer Training</title>
		<link>http://iPhoneDeveloperTips.com/training/pragmatic-studio-iphoneipad-developer-training.html</link>
		<comments>http://iPhoneDeveloperTips.com/training/pragmatic-studio-iphoneipad-developer-training.html#comments</comments>
		<pubDate>Thu, 01 Jul 2010 18:31:39 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6478</guid>
		<description><![CDATA[If you are looking for the right opportunity to quickly get up to speed on developing iPhone/iPad applications, look no further. The Pragmatic Studio is offering a 4-day, hands-on iPhone/iPad course in Santa Clara, California on August 17-20, 2010. Matt Drance and Daniel Steinberg, two seasoned developers and authors, are delivering the course. With this [...]]]></description>
			<content:encoded><![CDATA[<p><a  target="_blank"  href="http://iphonedevelopertips.com/?wp_ct=29"><img class="alignleft" style="margin: 3px;" src="http://iPhonedevelopertips.com/wp-content/uploads/2010/07/pragmaticiPhone-125x125.png" alt="Pragmatic Studio iPhone/iPad Training" width="125" height="125" /></a>If you are looking for the right opportunity to quickly get up to speed on developing iPhone/iPad applications, look no further. The <a  target="_blank"  href="http://iphonedevelopertips.com/?wp_ct=29">Pragmatic Studio</a> is offering a 4-day, hands-on <a  target="_blank"  href="http://iphonedevelopertips.com/?wp_ct=29">iPhone/iPad course</a> in Santa Clara, California on August 17-20, 2010.</p>
<p>Matt Drance and Daniel Steinberg, two seasoned developers and authors, are delivering the course. With this training under your belt, you&#8217;ll cut to the chase and start building your own iPhone/iPad apps in no time!</p>
<h5>Pragmatic Studio iPhone/iPad Topics</h5>
<p>You&#8217;ll learn how to use the major tools and APIs in the iPhone SDK 4 (the latest version), and how they all fit together to build iPhone/iPad apps like the pros.</p>
<p>* Intro to Objective-C<br />
* Xcode and Interface Builder<br />
* Cocoa Touch APIs and Design Patterns<br />
* View Controllers<br />
* Navigation and Tab Bar Controllers<br />
* Table Views<br />
* Keyboard Input<br />
* Gesture Recognizers<br />
* Animation<br />
* Core Data<br />
* Custom Graphics<br />
* Performance and Debugging</p>
<p>This course is a great way to dive into the latest iPhone tools and SDK! <a  target="_blank"   href="http://iphonedevelopertips.com/?wp_ct=29">Reserve your seat</a> by July 17th and save $300 on early registration!</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/training/pragmatic-studio-iphoneipad-developer-training.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSNotification, UserInfo and Object Methods</title>
		<link>http://iPhoneDeveloperTips.com/cocoa/nsnotification-userinfo-and-object-methods.html</link>
		<comments>http://iPhoneDeveloperTips.com/cocoa/nsnotification-userinfo-and-object-methods.html#comments</comments>
		<pubDate>Thu, 01 Jul 2010 11:33:55 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6450</guid>
		<description><![CDATA[When working with an NSNotification object, you&#8217;ll want to familiarize yourself the userInfo dictionary, which provides access to any additional objects that may be of interest to the receiver. Understanding the object method may also be helpful if you are using the same notification on more than one object. userInfo Dictionary Below I add an [...]]]></description>
			<content:encoded><![CDATA[<p>When working with an <strong>NSNotification</strong> object, you&#8217;ll want to familiarize yourself the <strong>userInfo</strong> dictionary, which provides access to any additional objects that may be of interest to the receiver. Understanding the <strong>object</strong> method may also be helpful if you are using the same notification on more than one object.<br />
<span id="more-6450"></span></p>
<h5>userInfo Dictionary</h5>
<p>Below I add an observer for <strong>MPMoviePlayerContentPreloadDidFinishNotification</strong>, which will send a message to the method <strong>moviePreloadDidFinish:</strong> when a <strong>MoviePlayerController</strong> object has finished playing:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">mp <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MPMoviePlayerController alloc<span style="color: #002200;">&#93;</span> initWithContentURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
                     selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePreloadDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
                     name<span style="color: #002200;">:</span>MPMoviePlayerContentPreloadDidFinishNotification 
                     object<span style="color: #002200;">:</span>mp<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Here&#8217;s how to access and print the <strong>userInfo</strong> dictionary from the notification object:</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> moviePlayBackDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>userInfo <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>notification userInfo<span style="color: #002200;">&#93;</span>;
&nbsp;
  NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MPMoviePlayerPlaybackDidFinishReasonUserInfoKey: %@&quot;</span>,
    <span style="color: #002200;">&#91;</span>userInfo objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MPMoviePlayerPlaybackDidFinishReasonUserInfoKey&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
  ...
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The value of <strong>MoviePlayerPlaybackDidFinishReasonUserInfoKey</strong> is an <strong>NSNumber</strong> object which contains an integer value specifying reason the playback finished. The possible range of return values are defined in <strong>MPMovieFinishReason</strong>, which is an enum type as shown here:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">enum</span> <span style="color: #002200;">&#123;</span>
   MPMovieFinishReasonPlaybackEnded,
   MPMovieFinishReasonPlaybackError,
   MPMovieFinishReasonUserExited
<span style="color: #002200;">&#125;</span>;
<span style="color: #a61390;">typedef</span> NSInteger MPMovieFinishReason;</pre></div></div>

<p>Pulling all this together, you could write something similar to the following to check if the user stopped playback of the movie:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>userInfo objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MPMoviePlayerPlaybackDidFinishReasonUserInfoKey&quot;</span><span style="color: #002200;">&#93;</span> intValue<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> MPMovieFinishReasonUserExited<span style="color: #002200;">&#41;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;User stopped playback&quot;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<h5>object Method</h5>
<p>One more handy method within <strong>NSNotification</strong> is the method <strong>object</strong>, which will return the object (as type <strong>id</strong>) that is associated with the notification. For example, check out the code below that sets up the notification, pay attention to the last parameter <strong>mp</strong> which is assigned to the <strong>object</strong> parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">mp <span style="color: #002200;">=</span>  <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MPMoviePlayerController alloc<span style="color: #002200;">&#93;</span> initWithContentURL<span style="color: #002200;">:</span>movieURL<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self 
                     selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>moviePreloadDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> 
                     name<span style="color: #002200;">:</span>MPMoviePlayerContentPreloadDidFinishNotification 
                     object<span style="color: #002200;">:</span>mp<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Within the method called by the selector, you can now access the object passed in by querying the <strong>object</strong> method:</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> moviePlayBackDidFinish<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification 
<span style="color: #002200;">&#123;</span>
  MPMoviePlayerController <span style="color: #002200;">*</span>mpObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>MPMoviePlayerController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#91;</span>notification object<span style="color: #002200;">&#93;</span>; 
...</pre></div></div>

<p><strong>mpObject</strong> will point to the <strong>mp</strong> object defined in the previous code block &#8211; using the <strong>object</strong> method you can retrieve a pointer to the object that made the original notification request.</p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/cocoa/nsnotification-userinfo-and-object-methods.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Announcing iPhone/iPad DevCon 2010 : Sept 27th through 29th in San Diego, California</title>
		<link>http://iPhoneDeveloperTips.com/announcements/announcing-iphoneipad-devcon-2010-sept-27th-through-29th.html</link>
		<comments>http://iPhoneDeveloperTips.com/announcements/announcing-iphoneipad-devcon-2010-sept-27th-through-29th.html#comments</comments>
		<pubDate>Tue, 29 Jun 2010 10:54:20 +0000</pubDate>
		<dc:creator>John Muchow</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=6407</guid>
		<description><![CDATA[BZ Media, publisher of SD Times, is proud to announce the iPhone/iPad DevCon being held September 27th &#8211; 29th, 2010 in sunny San Diego, California. iPhone DevCon has over 45 sessions to choose from, covering everything from design and development to marketing of iPhone and iPad applications. Beyond the comprehensive selection of workshops and classes, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iphonedevcon.com/PDFs/iPhoneiPadDevCon_CATALOG.pdf"><img class="alignright" src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/06/iPhoneDevConCatalog.png" alt="" width="133" height="137" /></a><a href="http://bzmedia.com/" target="_blank">BZ Media</a>, publisher of <a href="http://sdtimes.com/" target="_blank">SD Times</a>, is proud to announce the <a href="http://iphonedevelopertips.com/?wp_ct=28" target="_blank">iPhone/iPad DevCon</a> being held September 27th &#8211; 29th, 2010 in sunny San Diego, California.</p>
<p>iPhone DevCon has over 45 sessions to choose from, covering everything from design and development to marketing of iPhone and iPad applications.</p>
<p>Beyond the comprehensive selection of workshops and classes, you won&#8217;t want to miss the <a href="http://www.iphonedevcon.com/keynotes.html" target="_blank">keynote presentations</a> from two highly regarded Cocoa/iPhone developers: Aaron Hillegass, CEO of Big Nerd Ranch and author of the best-selling book Cocoa Programming, and Mike Lee, cofounder of Tapulous, creators of  Tap Tap Revenge.</p>
<p>If you <a href="http://www.iphonedevcon.com/registration.html" target="_blank">register by July 30th</a> you can save $450 over the full price registration!</p>
<p><a href="http://iphonedevelopertips.com/?wp_ct=28" target="_blank"><img src="http://iPhoneDeveloperTips.com/wp-content/uploads/2010/06/iphonedevcon.png" alt="" width="575" height="167" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://iPhoneDeveloperTips.com/announcements/announcing-iphoneipad-devcon-2010-sept-27th-through-29th.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
