<?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>richard hyland &#187; iPhone</title>
	<atom:link href="http://www.richardhyland.com/diary/category/computers-internet/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardhyland.com/diary</link>
	<description>random ramblings of a web, windows and iphone developer, oh and amateur photographer</description>
	<lastBuildDate>Mon, 01 Aug 2011 14:45:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<cloud domain='www.richardhyland.com' port='80' path='/diary/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>User Location and your own annotations in a MKMapView</title>
		<link>http://www.richardhyland.com/diary/2011/08/01/user-location-and-your-own-annotations-in-a-mkmapview/</link>
		<comments>http://www.richardhyland.com/diary/2011/08/01/user-location-and-your-own-annotations-in-a-mkmapview/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 14:41:49 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=629</guid>
		<description><![CDATA[I&#8217;ve spend a while working this one out. For a long time I&#8217;ve had a MKMapView to display pins dropped in specific places on a map. I&#8217;ve done this through the delegate method -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id) annotation { MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil]; // Some customisation goes here [annotation autorelease]; return annotation; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spend a while working this one out.</p>
<p>For a long time I&#8217;ve had a MKMapView to display pins dropped in specific places on a map.</p>
<p>I&#8217;ve done this through the delegate method</p>
<pre name="code">-(MKAnnotationView *)mapView:(MKMapView *)mapView  viewForAnnotation:(id) annotation {
  MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
 // Some customisation goes here
 [annotation autorelease];
 return annotation;
}</pre>
<p>That&#8217;s all very will but then I decided it&#8217;d be nice to show the user&#8217;s current location on the map as well, you know the lovely blue pin with accuracy circle around it.  </p>
<p>Well enabling this looks very simple.  </p>
<pre class="cpp" name="code">mapView.showsUserLocation = YES;</pre>
<p>Now I have custom objects in my annotation subclasses so I can reference them easily later. With this, however, if you compile and try to run, when the view loads you&#8217;ll get a crash with this error to the debugger.</p>
<blockquote><p>-[MKUserLocation getTagId]: unrecognized selectory sent to instance</p></blockquote>
<p>It turns out the way to get this to work is to include at the top of the delegate method the following line</p>
<pre class="cpp" name="code">
if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;
</pre>
<p>Compile and run and all will work fine</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2011/08/01/user-location-and-your-own-annotations-in-a-mkmapview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Logging in Obj-C</title>
		<link>http://www.richardhyland.com/diary/2010/12/07/custom-logging-in-obj-c/</link>
		<comments>http://www.richardhyland.com/diary/2010/12/07/custom-logging-in-obj-c/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 18:59:37 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=596</guid>
		<description><![CDATA[If you&#8217;ve used Objective-C for Mac or iOS development you&#8217;re probably familiar with NSLog(); to log to the console. Well that is fantastic for development, but you don&#8217;t really want to output your debugging logs on distributed iOS apps do you? It would be a real pain to remove every instance of NSLog from your [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used Objective-C for Mac or iOS development you&#8217;re probably familiar with NSLog(); to log to the console.</p>
<p>Well that is fantastic for development, but you don&#8217;t really want to output your debugging logs on distributed iOS apps do you?</p>
<p>It would be a real pain to remove every instance of NSLog from your code everytime you wish to distribute your app.  Well you can solve this with a custom logger.</p>
<p>In your Prefix.pch file add the following bit of code</p>
<pre class="cpp" name="code">
#ifdef DEBUG
#  define RHLog(...) NSLog(__VA_ARGS__)
#else
#  define RHLog(...) ;
#endif
</pre>
<p>Then whenever DEBUG is set (either by adding DEBUG to your pre-processor macros, or using the -DDEBUG flag) instead of calling </p>
<pre class="cpp" name="code">NSLog(@"String: %@", stringValue);</pre>
<p>you can call</p>
<pre class="cpp" name="code">RHLog(@"String: %@", stringValue);</pre>
<p>And when in debug mode the string will log to the console, in Release, Ad-Hoc and Distribution builds it won&#8217;t</p>
<p>However you can go one further than this and actually produce a much nicer logging function using </p>
<pre class="cpp" name="code">#ifdef DEBUG
#   define RHLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define RHLog(...)
#endif</pre>
<p>and when you call your function like so</p>
<pre class="cpp" name="code">RHLog(@"Testing");</pre>
<p>You&#8217;ll see the following in your console</p>
<pre class="cpp" name="code">-[AppDelegate startup] [Line 123] Testing</pre>
<p><em>* Image Credit <a href="http://commons.wikimedia.org/wiki/File:Bildschirmfoto_2010-08-05_um_20.56.34.png">Fryhstyxei</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2010/12/07/custom-logging-in-obj-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The iPhone App Piracy Problem</title>
		<link>http://www.richardhyland.com/diary/2010/08/18/the-iphone-app-piracy-problem/</link>
		<comments>http://www.richardhyland.com/diary/2010/08/18/the-iphone-app-piracy-problem/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 07:07:11 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=589</guid>
		<description><![CDATA[The iOS (that&#8217;s the iPhone, iPad and iPod Touch) AppStore has a problem. A piracy problem. If you have a jailbroken iPhone, that is one where you have run a bit of software to allow you to download apps outside of the AppStore then you may have come across pirated apps, you may not have [...]]]></description>
			<content:encoded><![CDATA[<p>The iOS (that&#8217;s the iPhone, iPad and iPod Touch) AppStore has a problem.</p>
<p>A piracy problem.</p>
<p>If you have a jailbroken iPhone, that is one where you have run a bit of software to allow you to download apps outside of the AppStore then you may have come across pirated apps, you may not have installed them but you&#8217;re probably aware of them.</p>
<p>Before I talk about the morality of piracy, let me address the question of why</p>
<h2>Why do pirates crack apps?</h2>
<p>This is an interesting question and to understand the piracy we must address the motivations</p>
<h3>1) Try before you buy</h3>
<p>I&#8217;ve heard this many times for people&#8217;s justifications as to why they crack apps.</p>
<p>Apple doesn&#8217;t offer any form of demo or free trial for Apps and so I can understand this motivation.  However there are two problems with this justification</p>
<ol>
<li>Many of the popular apps already provide a &#8216;try before you buy&#8217; in the form of a free &#8216;lite&#8217; app from the App Store itself</li>
<li>The conversion rate from cracked to paid is less than 0.5% (<a href="http://www.pinchmedia.com/blog/piracy-in-the-app-store-from-360idev/" target="_blank">source</a>)</li>
</ol>
<p>The conversion rate of cracked to paid is incredibly low which simply blows any form of arguement of try before you buy out of the water&#8230; it&#8217;s total rubbish.</p>
<p>Sure some of you out there have done so, and I applaud you for that, but unfortunately you are in the very small minority.</p>
<h3>2) A hatred of DRM</h3>
<p>DRM (or Digital Rights Management) is an encryption and licensing technique used on DVD&#8217;s, BluRays, some iTunes purchases, etc and Apps from the AppStore.</p>
<p>It&#8217;s a system, whether you like it or not, that restricts where you can and can&#8217;t install your purchase. How many times you can install it and then what you can do or modify in it once you have installed it.</p>
<p>Cracking an App on the iPhone removes this encryption and DRM.</p>
<p>Again I can understand this, if someone wants to remove the DRM and encryption for their own use, then for me this is fair enough and I have no problem with them doing this.</p>
<p>But how, I ask, did that app end up on file sharing sites and specialised cracked app repos.  Opps sorry you&#8217;ve lost your argument again.  The minute you share that DRM free version you&#8217;ve lost my respect again and you&#8217;ve breached my copyright.</p>
<h3>3) A fundamental belief that software should be free</h3>
<p>This is the last category and it&#8217;s either that the user has a belief that all software should be free or they simply don&#8217;t care about the law.</p>
<p>The former, is a belief that a number of people hold, however who are they to decide under what license my software should be released.  Did they write it? Do they own the copyright? <strong>NO</strong> they don&#8217;t. So they do <strong>NOT</strong> get to decide under what terms my software is available.</p>
<p>If they want to write their own software and release it for free I will defend their right to choose that path, but at the same time I will defend anyone who decides to charge for their software, as it is their right to do so.</p>
<h2>The rights of a developer</h2>
<p>A developer works, a developer has a family, a developer has a mortgage, a developer has taxes to pay, a developer has computers to purchase to develop on, a developer has software to purchase (developers don&#8217;t use pirated software to develop commercial software, that would be hypocritical wouldn&#8217;t it!), a developer has servers to license, domains to buy, food to put on the table.  Do you see where I am going with this.</p>
<p>That push notification feature you love, that scheduling feature you love so much.  A server is involved there and who pays for that? Well either the developer makes a loss paying for it, or legitimate customers have to pay more simply to cover the cost of you giving away the app for free.</p>
<p>A cracker in all likelyhood isn&#8217;t a developer, they probably have a job outside IT.</p>
<p>Think about it this way, if you work in an office and an intern comes in and claims credit for all your work and doesn&#8217;t get paid, but because they&#8217;ve claimed credit for all your work you don&#8217;t get paid either, in fact you get made redunant is that fair? Is that right? No of course it&#8217;s not.</p>
<p>Developers do not work for free, they have the same bills and financial outgoings as anyone else.  So a message to the app crackers who distribute cracked apps out there, what gives you the right to give away my software for free and prevent me from paying my mortgage this month? ABSOLUTELY NONE, you are thieves&#8230; end of story.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2010/08/18/the-iphone-app-piracy-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to harness the Retina Display in your app</title>
		<link>http://www.richardhyland.com/diary/2010/07/15/how-to-harness-the-retina-display-in-your-app/</link>
		<comments>http://www.richardhyland.com/diary/2010/07/15/how-to-harness-the-retina-display-in-your-app/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 23:00:42 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=585</guid>
		<description><![CDATA[It is remarkably easy to do so and I implore all all iPhone developers to please upgrade all their apps to support the Retina Display on the iPhone 4, otherwise your app just looks blurry. What Apple achieved with the Retina Display is a remarkable feat. The screen is still exactly the same size of [...]]]></description>
			<content:encoded><![CDATA[<p>It is remarkably easy to do so and I implore all all iPhone developers to please upgrade all their apps to support the Retina Display on the iPhone 4, otherwise your app just looks blurry.</p>
<p>What Apple achieved with the Retina Display is a remarkable feat. The screen is still exactly the same size of 3.5 inches but where you used to have 1 pixel you now have 4.  This means UI elements are scaled exactly by 2.</p>
<p>Developers were always told to design for a screen resolution of 320&#215;480 pixels, so don&#8217;t I need to change my UIViewControllers to have a different size?</p>
<p>Well no, and this is how Apple have been incredibly clever. The screen dimensions are now 320&#215;480 points, and not pixels so in your UIViewController you still have the size 320&#215;480. With me so far?</p>
<p><strong>Images</strong></p>
<p>Ok so lets say I have an image that needs to span the width of the screen and is only 100 pixels high on an iPhone 3G or 3Gs we simply embed an image of 320pixels by 100pixels.  So that image that we&#8217;ve called banner.png, for example, looks perfect on those old devices but they look blurry on the iPhone 4.</p>
<p>I can hear you asking, if the screen is 320points wide but is actually 640pixels wide, how do I provide both an iPhone 4 and iPhone 3G(s) version of this and how much code does it take.</p>
<p>Well my answer is, very easy and zero, that&#8217;s right, <strong>zero</strong> code modifications.</p>
<p>Now you did have a high resolution, or vector version of your artwork right? Ok well open it up and scale it to exactly double the size of the original file. So you&#8217;ll now have an image that is 640&#215;200 pixels and save it as banner@2x.png (as the original was called banner.png). Add the new image to your resources in your XCode project.</p>
<p>You can call your image in exactly the same way as before</p>
<pre class="cpp" name="code">UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,100)];
[myImage setImage:[UIImage imageNamed:@"banner.png"]];
[self.view addSubview:myImage];
[myImage release];</pre>
<p>When you run your app on your iPhone 4 (or the iPhone 4) simulator the image will magically use the banner@2x.png version instead.  Clever isn&#8217;t it!</p>
<p><strong>Default splash images</strong></p>
<p>This is exactly the same as for images, just include a Default@2x.png image in your bundle and the iPhone 4 will use it instead.</p>
<p><strong>Springboard App Icon</strong></p>
<p>Ok now this one is a little more complicated, but not by much.  If you&#8217;ve already designed a Universal (iPhone and iPad) app then you&#8217;ll be familiar with this technique, and actually there are a couple of ways to do it but I&#8217;ll explain the one from the Apple Docs.</p>
<p>If you want to still provide support to iOS 3.1.x and below you&#8217;ll still need a</p>
<pre class="cpp" name="code">CFBundleIconFile</pre>
<p>with Icon.png in it for your Info.plist but you should now also include an array entry of</p>
<pre class="cpp" name="code">CFBundleIconFiles</pre>
<p>Include an Icon.png file, this is your non-iPhone 4 57&#215;57 file<br />
Include an Icon@2x.png file, this is your iPhone 4 114&#215;114 file.</p>
<p>Yep once again it really is that simple.</p>
<p><strong>Conclusion</strong></p>
<p>If you have an app that simply uses SDK UI Elements and/or images, which the majority of iPhone app do, then you simply have no excuse not to support the Retina Display&#8230; so what are you waiting for, go cut graphics and submit!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2010/07/15/how-to-harness-the-retina-display-in-your-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a mini map using MapKit on the iPhone</title>
		<link>http://www.richardhyland.com/diary/2009/11/20/creating-a-mini-map-using-mapkit-on-the-iphone/</link>
		<comments>http://www.richardhyland.com/diary/2009/11/20/creating-a-mini-map-using-mapkit-on-the-iphone/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 13:03:38 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=571</guid>
		<description><![CDATA[So as promised here is the final part of my MapKit tips and tricks using the iPhone SDK. Sorry it&#8217;s a little later than I intended as I wanted my version of the feature live in the AppStore before I published the article. So we&#8217;ve seen before how to create a simple map, well now [...]]]></description>
			<content:encoded><![CDATA[<p>So as promised here is the final part of my MapKit tips and tricks using the iPhone SDK.</p>
<p>Sorry it&#8217;s a little later than I intended as I wanted my version of the feature live in the AppStore before I published the article.</p>
<p>So we&#8217;ve seen before how to create a simple map, well now let&#8217;s see how to create a really small thumbnail sized version like this <em>(sorry there is no anti-aliasing, the iPhone simulator doesn&#8217;t support it on MapKit, works fine on the actual device though!)</em></p>
<p><img class="aligncenter size-full wp-image-573" title="smallmap" src="http://www.richardhyland.com/diary/wp-content/uploads/2009/11/smallmap.jpg" alt="smallmap" width="111" height="58" /></p>
<p>In my version, I take this code and add it to a much larger view controller like this</p>
<p><img class="aligncenter size-full wp-image-572" title="bigmap" src="http://www.richardhyland.com/diary/wp-content/uploads/2009/11/bigmap.jpg" alt="bigmap" width="322" height="477" /></p>
<p><em>A bit of shameless plugging: this comes from <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323248061&#038;mt=8&#038;s=143441">Tweetings</a> for the iPhone</em></p>
<p>I won&#8217;t cover anything more to this other than getting the map to a state where you can add it to any view of yours using the [object addSubview:mapView] call.</p>
<p><strong>Generating the map</strong></p>
<p>This is the same as generating a large map, that we&#8217;ve covered before, except the frame will be of a different size, however the most important factor here is we are going to scale the map</p>
<pre class="cpp" name="code">
float scaleBy = 0.80;
MKMapView *mapView = [[[MKMapView alloc] initWithFrame:CGRectMake(-5, 0, 100/ scaleBy, 50/scaleBy)] autorelease];
mapView.delegate=self;
mapView.layer.cornerRadius = 10.0; // Make the corners rounded
mapView.opaque = NO; // If you are using in a UITableView never set to YES!
mapView.scrollEnabled = NO; // Don't allow user interaction
mapView.zoomEnabled = NO;
mapView.layer.borderColor = [UIColor colorWithWhite:0.0f alpha:0.5f].CGColor;
mapView.layer.borderWidth = 1.0f/ scaleBy;
mapView.layer.transform = CATransform3DMakeScale(scaleBy, scaleBy, 1.0);
</pre>
<p>At this point you can actually now add it to your view and set any other properties in the same way as you would normally, job done&#8230;. yes it really is that simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/11/20/creating-a-mini-map-using-mapkit-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add a pin to embedded map</title>
		<link>http://www.richardhyland.com/diary/2009/10/27/how-to-add-a-pin-to-embedded-map/</link>
		<comments>http://www.richardhyland.com/diary/2009/10/27/how-to-add-a-pin-to-embedded-map/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:17:10 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=555</guid>
		<description><![CDATA[Part one of this section on MapKits showed how to embed a map and place a floating toolbar for switching the map views, however it didn&#8217;t cover how to drop the pin where you wanted it. Create the Object First lets create a new NSObject for the place mark. Let&#8217;s call it &#8216;PlaceMark&#8217; PlaceMark.h #import [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.richardhyland.com/diary/2009/10/17/how-to-embed-a-map-on-the-iphone/">Part one</a> of this section on MapKits showed how to embed a map and place a floating toolbar for switching the map views, however it didn&#8217;t cover how to drop the pin where you wanted it.<br />
<img class="aligncenter size-full wp-image-547" title="MKMapKit" src="http://www.richardhyland.com/diary/wp-content/uploads/2009/10/map.png" alt="MKMapKit" width="320" height="412" /></p>
<h2>Create the Object</h2>
<p>First lets create a new NSObject for the place mark. Let&#8217;s call it &#8216;PlaceMark&#8217;</p>
<p><em>PlaceMark.h</em></p>
<pre class="cpp" name="code">
#import &lt;Foundation/Foundation.h&gt;
#import &lt;MapKit/MapKit.h&gt;

@interface PlaceMark : NSObject<MKAnnotation> {
	CLLocationCoordinate2D coordinate;
	NSString *subtitletext;
	NSString *titletext;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (readwrite, retain) NSString *titletext;
@property (readwrite, retain) NSString *subtitletext;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
-(void)setTitle:(NSString*)strTitle;
-(void)setSubTitle:(NSString*)strSubTitle;

@end
</pre>
<p><em>PlaceMark.m</em></p>
<pre class="cpp" name="code">
#import "PlaceMark.h"

@implementation PlaceMark
@synthesize coordinate, titletext, subtitletext;

- (NSString *)subtitle{
	return subtitletext;
}
- (NSString *)title{
	return titletext;
}

-(void)setTitle:(NSString*)strTitle {
	self.titletext = strTitle;
}

-(void)setSubTitle:(NSString*)strSubTitle {
	self.subtitletext = strSubTitle;
}

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
	coordinate=c;
	return self;
}
@end
</pre>
<h2>Adding a pin to your map</h2>
<p>Firstly remember to add</p>
<pre class="cpp" name="code">
#import "PlaceMark.h"
</pre>
<p>To your map controller, from the previous example inside the displayMap function under the region.center call</p>
<pre class="cpp" name="code">
PlaceMark *addAnnotation = [[[PlaceMark alloc] initWithCoordinate:location] retain];
[addAnnotation setTitle:@"The Pin Title"];
[addAnnotation setSubTitle:@"The pin subtitle goes here"];

[mapView addAnnotation:addAnnotation];
</pre>
<p>Then create the following delegate method</p>
<pre name="code" class="cpp">
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;) annotation{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
	[annView setSelected:YES];
	annView.pinColor = MKPinAnnotationColorPurple;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}
</pre>
<p>Voila you now have a pin dropped on the map and automatically selected.  If you don&#8217;t want the title automatically displayed then change</p>
<pre name="code" class="cpp">
[annView setSelected:YES];
</pre>
<p><em>The final part demonstrates how to create a <a href="http://www.richardhyland.com/diary/2009/11/20/creating-a-mini-map-using-mapkit-on-the-iphone/">mini map</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/10/27/how-to-add-a-pin-to-embedded-map/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to embed a map on the iPhone</title>
		<link>http://www.richardhyland.com/diary/2009/10/17/how-to-embed-a-map-on-the-iphone/</link>
		<comments>http://www.richardhyland.com/diary/2009/10/17/how-to-embed-a-map-on-the-iphone/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 19:05:46 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=548</guid>
		<description><![CDATA[In the first of a few posts I intend to make I&#8217;ll demonstrate some examples using the iPhone SDK. This example will demonstrate how to embed a map, using the MKMapKit framework inside a UIView using the iPhone SDK. Note you must be using iPhone OS 3.0 or higher for this to work. The ultimate [...]]]></description>
			<content:encoded><![CDATA[<p>In the first of a few posts I intend to make I&#8217;ll demonstrate some examples using the iPhone SDK.</p>
<p>This example will demonstrate how to embed a map, using the MKMapKit framework inside a UIView using the iPhone SDK.  Note you must be using iPhone OS 3.0 or higher for this to work.  The ultimate aim is to get a UIView that looks similar to this.</p>
<p>For this example I will assume you are already familiar with navigation and UIViews in the SDK (and so I won&#8217;t cover how to get the navigation bar at the top of this screenshot)</p>
<p><img class="aligncenter size-full wp-image-547" title="MKMapKit" src="http://www.richardhyland.com/diary/wp-content/uploads/2009/10/map.png" alt="MKMapKit" width="320" height="412" /></p>
<h2>Add the framework</h2>
<p>First up you must go to the Frameworks folder of your XCode project and add the existing framework of MKMapKit.</p>
<p>Then inside the header file for your view add</p>
<pre class="cpp" name="code">
#import &lt;MapKit/MapKit.h&gt;
</pre>
<h2>Adding MapKit references to the header</h2>
<p>Now we must add the mapKit instance to the header as well as the MapKit delegate</p>
<pre class="cpp" name="code">
@interface MapKitViewController : UIViewController &lt;MKMapViewDelegate&gt; {
	MKMapView *mapView;
}
-(void)displayMap;
</pre>
<h2>Initialize the Map</h2>
<pre class="cpp" name="code">
- (void)viewDidLoad {
	mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
	mapView.delegate=self;

	[self.view addSubview:mapView];
	[NSThread detachNewThreadSelector:@selector(displayMap) toTarget:self withObject:nil];
}

-(void)displayMap {
	MKCoordinateRegion region;
	MKCoordinateSpan span;
	span.latitudeDelta=0.2;
	span.longitudeDelta=0.2;

	CLLocationCoordinate2D location;
	location.latitude = -35;
	location.longitude = 146.2381;
	region.span=span;
	region.center=location;

	[mapView setRegion:region animated:TRUE];
	[mapView regionThatFits:region];
}

- (void)dealloc {
	[mapView release];
        [super dealloc];
}
</pre>
<p>This will give us a map fitting the screen with the region and zoom level set to best fit the coordinates given.  Note that I have physically defined the coordinates here in this example, you can use something like the Google GeoCode API to convert addresses, etc to coordinates.  I won&#8217;t cover that here.</p>
<h2>Changing the map type</h2>
<p>In the example above is a tool bar allowing you to switch map types</p>
<p>Let&#8217;s define the toolbar in the header file inside the @implementation</p>
<pre class="cpp" name="code">
UISegmentedControl *buttonBarSegmentedControl;
</pre>
<p>Now inside the main code inside ViewDidLoad we add</p>
<pre class="cpp" name="code">
buttonBarSegmentedControl = [[UISegmentedControl alloc] initWithItems:
	[NSArray arrayWithObjects:@"Standard", @"Satellite", @"Hybrid", nil]];
	[buttonBarSegmentedControl setFrame:CGRectMake(30, 10, 280-30, 30)];
        buttonBarSegmentedControl.selectedSegmentIndex = 0.0;	// start by showing the normal picker
	[buttonBarSegmentedControl addTarget:self action:@selector(toggleToolBarChange:) forControlEvents:UIControlEventValueChanged];
	buttonBarSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
	buttonBarSegmentedControl.backgroundColor = [UIColor clearColor];
	[buttonBarSegmentedControl setAlpha:0.8];

	[self.view addSubview:buttonBarSegmentedControl];
</pre>
<p>Then we must add the function for what happens when we tap on the tool bar</p>
<pre class="cpp" name="code">
- (void)toggleToolBarChange:(id)sender
{
	UISegmentedControl *segControl = sender;

	switch (segControl.selectedSegmentIndex)
	{
		case 0:	// Map
		{
			[mapView setMapType:MKMapTypeStandard];
			break;
		}
		case 1: // Satellite
		{
			[mapView setMapType:MKMapTypeSatellite];
			break;
		}
		case 2: // Hybrid
		{
			[mapView setMapType:MKMapTypeHybrid];
			break;
		}
	}
}
</pre>
<p>In the <a href="http://www.richardhyland.com/diary/2009/10/27/how-to-add-a-pin-to-embedded-map/">next example</a>, I&#8217;ll cover how to add the annotations (the small pins) to the map</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/10/17/how-to-embed-a-map-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The iTunes App Store review process</title>
		<link>http://www.richardhyland.com/diary/2009/08/25/the-itunes-app-store-review-process/</link>
		<comments>http://www.richardhyland.com/diary/2009/08/25/the-itunes-app-store-review-process/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 08:29:10 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=533</guid>
		<description><![CDATA[Being a small fry iPhone app developer, that being I do so in my own spare time because I like developing apps for the iPhone, I&#8217;ve simply got to comment about the App Store review process as it stands. I won&#8217;t make any individual comments about my personal rejections I&#8217;ve had except to say. I [...]]]></description>
			<content:encoded><![CDATA[<p>Being a small fry iPhone app developer, that being I do so in my own spare time because I like developing apps for the iPhone, I&#8217;ve simply got to comment about the App Store review process as it stands.</p>
<p>I won&#8217;t make any individual comments about my personal rejections I&#8217;ve had except to say.  I have had a number of rejections.</p>
<p>One update got rejected numerous times because apparently if you use a UIWebView where the user<em> might</em> be able to get to Google and therefore access pictures of &lt;shock&gt;naked people&lt;/shock&gt; then you have to rate your App as 17+.  Let us ignore the fact that they could just close your app and go to mobile Safari shall we, it would be by far easier?</p>
<p>Another one I reason I&#8217;ve been rejected for features not doing something Apple think they should, yet that very same feature was actually in the version before it&#8230;. still on sale in the App Store.  Inconsistent reviewing doesn&#8217;t even begin to cover it!</p>
<p>So this leads me on to a blog post I read today from <a href="http://joehewitt.com/post/innocent-until-proven-guilty/" target="_blank">Joe Hewitt</a>.  For anyone who doesn&#8217;t know who Joe is, he is the guy who wrote the amazing Facebook app for the iPhone.</p>
<blockquote><p>I have only one major complaint with the App Store, and I can state it quite simply: the review process needs to be eliminated completely.</p>
<p>Does that sound scary to you, imagining a world in which any developer can just publish an app to your little touch screen computer without Apple&#8217;s saintly reviewers scrubbing it of all evil first? Well, it shouldn&#8217;t, because there is this thing called the World Wide Web which already works that way, and it has served millions and millions of people quite well for a long time now.</p></blockquote>
<p>Go and read his <a href="http://joehewitt.com/post/innocent-until-proven-guilty/" target="_blank">excellent post now</a> at what I totally agree with&#8230;. especially as I have one app that I originally submitted a month ago, awaiting approval!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/08/25/the-itunes-app-store-review-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UIActionSheet&#8217;s cancel button presses not detected properly</title>
		<link>http://www.richardhyland.com/diary/2009/07/22/uiactionsheets-cancel-button-presses-not-detected-properly/</link>
		<comments>http://www.richardhyland.com/diary/2009/07/22/uiactionsheets-cancel-button-presses-not-detected-properly/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 18:09:17 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=515</guid>
		<description><![CDATA[Last night I came across a really annoying bug with UIActionSheet when used in conjunction with a UITabBarController. Basically there is a killer bug which means you can&#8217;t click the Cancel button on a UIActionSheet and forces the user to either close the App or use one of the destructive action buttons to get rid [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I came across a really annoying bug with UIActionSheet when used in conjunction with a UITabBarController.</p>
<p>Basically there is a killer bug which means you can&#8217;t click the Cancel button on a UIActionSheet and forces the user to either close the App or use one of the destructive action buttons to get rid of the alert.</p>
<p>It appears to be a changed from OS &lt;= 2.1 to &gt;= 2.2. In iPhone OS 2.1 and earlier, the UIActionSheet comes up from the top of the tab bar, but in 2.2, it comes up from the bottom of the tab bar, and thus covers the tab view but the tab view still takes focus.  If you try to press the cancel button below the top of the tab bar (barely visible through the semi-transparent UIActionSheet), the press does not register. If you click above the underlying tab bar, the press does work.</p>
<p>This is how you fix it.</p>
<p>1) In your AppDelegate.h function</p>
<pre class="cpp" name="code">+ (UITabBarController *)tabbarController;</pre>
<p>Note that tabbarController should be different than your ACTUAL UITabBarController name.</p>
<p>Next edit your AppDelegate.m functiuon and above your @implementation</p>
<pre class="cpp" name="code">static AppDelegate *s_appdelegate = nil;

@implementation AppDelegate</pre>
<p>Inside applicationDidFinishLaunching add</p>
<pre class="cpp">s_appdelegate = self;</pre>
<p>At the bottom of AppDelegate.m before @end add</p>
<pre class="cpp">+ (UITabBarController *)tabbarController
{
	return s_appdelegate ? s_appdelegate.tabBarController : nil;
}</pre>
<p>Finally in your child view in which you wish to display your UIActionSheet add</p>
<pre class="cpp" name="code">	UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Delete?"
		delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Yes" otherButtonTitles:nil, nil];

	UIView *viewBase = self.view;
	viewBase = [[AppDelegate tabbarController] view];
	[sheet showInView:viewBase];
	[sheet release];</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/07/22/uiactionsheets-cancel-button-presses-not-detected-properly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone push problems on unlocked phones</title>
		<link>http://www.richardhyland.com/diary/2009/07/22/iphone-push-problems-on-unlocked-phones/</link>
		<comments>http://www.richardhyland.com/diary/2009/07/22/iphone-push-problems-on-unlocked-phones/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 17:40:36 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.richardhyland.com/diary/?p=518</guid>
		<description><![CDATA[I read an article today about Push Notifications being displayed on the wrong people&#8217;s phones. Now if the story is taken at face value then this would be a huge security flaw with the Apple Push Notification Service. However if you dig a little further you discover that it isn&#8217;t Apple&#8217;s problem at all, more [...]]]></description>
			<content:encoded><![CDATA[<p>I read an <a href="http://www.tuaw.com/2009/07/21/iphone-push-exploit-sends-aim-message-to-unintended-recipients/">article</a> today about Push Notifications being displayed on the wrong people&#8217;s phones. </p>
<p>Now if the story is taken at face value then this would be a huge security flaw with the Apple Push Notification Service.  However if you dig a little further you discover that it isn&#8217;t Apple&#8217;s problem at all, more the work of the unlocking community.</p>
<p>Now I&#8217;ll first start by explaining how the push notification service works.  When you first load an application with push notification enabled, the application makes a call to the APNS (Apple Push Notification Service) servers.  Those servers respond with a unique key for that device for push services. That unique key allows Apple to identify which device and which application to target for a push notification.</p>
<p>The App then communicates with the application&#8217;s author&#8217;s web servers and stores the key somewhere.  The author&#8217;s servers then use that key to push a JSON encoded payload the APNS servers and the notification gets displayed on the user&#8217;s phone.</p>
<p>With me so far?  So how does this break on unlocked iPhones?</p>
<p>Well unlocked / hacktivated phones haven&#8217;t actually been activated with Apple&#8217;s activations servers, they&#8217;ve simply been fooled into thinking that they have.</p>
<p>From what I&#8217;ve read about this situation is that the hacktivating / unlocking community have taken the key(s) from a properly activated device and put as part of the process.</p>
<p>So what is actually happening is that multiple phones are recieving legitimate push messages for the original key holder but not for them.</p>
<p>At present it would seem that push notifications simply won&#8217;t work on hacktivated / unlocked phones.</p>
<p>I guess the lesson is, if the software is written to prevent you from unlocking / by passing activation and then you do bypass it, then don&#8217;t expect everything to work properly!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhyland.com/diary/2009/07/22/iphone-push-problems-on-unlocked-phones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

