More Core Location [2] – device capabilities

A few days ago I posted the first of a short series of extra notes for my video2brain “iPhone and iOS Application Development Workshop” course. Now, despite finding myself back in the studio and recording like a demon, I present you with the second part:

Checking for other device capabilities

If your App needs to receive other types of location update information or relies on, for example, heading information, you’ll need to check that the user’s device can deliver this information too before you can use it in your App.

Heading information

+ (BOOL)headingAvailable

If you need to receive heading information then use the headingAvailable method of CLLocationManager to confirm that their device can provide this information. iOS devices without a compass will NOT be able to provide this data! Heading information is great to have if you’re implementing any form of augmented reality app where you need to overlay images on the iPhone screen – or even to give people more information about where they’re headed!

Region Monitoring

Region monitoring capability was added in iOS 4.0 and allows you to trigger a location update whenever a device enters a pre-defined region. This feature is great if you want to be able to implement some form of region tracking OR to provide the user with some form of reminder or alert (so called “GeoNotes”) – much like the new Reminders App with iOS 5.

+ (BOOL)regionMonitoringAvailable

and

+ (BOOL)regionMonitoringEnabled

For your App to be able to use Region Monitoring, the user’s device will have to support it – and the user will have to have enabled the service in their device Settings. If regionMonitoringAvailable returns NO then your App will not be able to monitor regions.

If the return value is YES but regionMonitoringEnabled returns NO then all is not lost: You can prompt your user to enable this setting by displaying a UIAlertView or other interface element, explaining why it’s important for your App to be able to receive this data.

Significant Location Change Monitoring

+ (BOOL)significantLocationChangeMonitoringAvailable

Device support for Significant Location Change Monitoring can be detected by using the CLLocationManager method significantLocationChangeMonitoringAvailable. A return value of NO will mean that you cannot monitor for these changes. Also an iOS 4.0 feature, Significant Location Change monitoring is only available on iPhones and iPads with a 3G cellular connection.

Significant Location Change Monitoring can be extremely useful for reducing the battery power consumption of your app when in the background. You can use notifications from Significant Location Change Monitoring to start tracking somebody more actively for, say, an exercise-related app and then pause location updates when they stay in one place for a while. Many sports apps use this to implement their “autopause” features and thereby help to reduce battery consumption.

That’s it for today. I’m heading back to the studio and will be back with more news and the third part of this series soon.

Until then, happy coding!

 

tags: , , , , , ,

Coming soon – Facebook Application Development, Learn by Video

My second video2brain course is due to be released soon!

This time I’ve put together a course to take you through the steps involved in building Facebook Applications – in both PHP and JavaScript and including examples of integrating Flash content for those of you who are itching to create the next Farmville ;-)

The course is the fruit of more than 3 years’ worth of Facebook Application development experience and a fun week’s stay in Graz last month and is packed full of example code and tips for everybody who wants to get into Facebook App development!

The course will, as you may have guessed from the box shot, be available in boxed DVD form together with an accompanying booklet packed with extra tips for Flash Application development for Facebook – an area that I’ve been heavily involved in from the beginnings of the Facebook Platform for Developers. One chapter in the booklet was written by my colleague and partner in crime at Substance, Neil Young, and covers more PHP and specifically AMFPHP Gateway implementation for Facebook Applications.

Drop me a line with your email address if you’d like a heads-up when the course is available or watch this space for news!

 

tags: , , , , ,

More Core Location [1] – basic settings

For those of you who’ve purchased and watched my video2brain “iPhone and iOS Application Development Workshop” course, I’ve decided to write a series of blog posts that serve to expand on the information contained in the course chapter on Core Location and Mapping. This is the first of those posts.

If you haven’t yet seen any of the course videos then you can check them out and purchase the course for the thoroughly ridiculous price of £21.99 via the “video courses” link at the top right of this page (the little TV) or by clicking here….

So. Here we go!

In the course chapter on Core Location and Mapping I showed you how you can find a user’s current location, use reverse-geocoding to show address information for that location and how to represent points on a map, including showing annotations, callouts and overlays.

In this series of blog posts I will highlight some other important aspects you should consider when using Core Location within your Apps and also take you through how to access and use headings data from devices with compass support.

Checking for available Services

It’s important that you check for the availability of Core Location Services and device support before simply coding away. Fail to explicitly check for service availability or device support and you’re paving the way for App crashes. Not only will your users be unimpressed, but you may well find that your new location-aware App is rejected from the App Store before your users can even experience a crash.

So, as usual, we need to make sure our code is water-tight.

Your first check should be to make sure that location services are enabled on the device via the CLLocationManager locationServicesEnabled method:

+	(BOOL)locationServicesEnabled 

While it’s possible that a user may have granted your App permission to use their location upon first use, they may have revoked this right at any point by changing settings on their device, as in the case of “Strobox” here:

If locationServicesEnabled returns NO then you can display an UIAlertView informing the user that they’ll need to grant permission to your App again so that you can access their location.

Not performing this check will mean that your user will be prompted with the standard permissions dialog when you first start location updates – potentially causing confusion if they had granted permission before and can’t remember revoking this permission in their settings.

Don’t forget the purpose property

Simply setting this String property will much increase the chances of your users granting location permissions to your App. It’s also courteous to explain to them why you need their location. The code we wrote in the myLocation App CoreLocationController Class for example:

- (id)init {
	self = [super init];

	if(self != nil) {
		self.locMgr = [[[CLLocationManager alloc] init] autorelease];
                self.locMgr.delegate = self;
		// set the purpose string to display a useful message in the permission dialog
		self.locMgr.purpose:@"myLocation needs to know your location so that it can report it";
 	}

	return self;
}

Resulted in an informative message being shown to users of the App within the standard prompt dialog:

In the next post of this series, I’ll talk a little about detecting device capabilities. Watch this space!

Meanwhile: Don’t forget to work through the course lessons on Core Location and Mapping ;-)

Happy coding!