The Map Kit Framework is what you use to add a map to your application. There are a number of classes found within the framework that let you provide a rich experience for your users. Today we will look at two of the basic ones. These are MKMapView and MKMapViewDelegate. We will add more tutorials over the coming weeks from the MapKit framework and when iOS 7 launches, we’ll begin adjusting the tutorials accordingly. [Read more…]
Core Location is a powerful framework that allows your apps to use location information. Mixed with the MapKit, you can create some powerful location based apps. Yesterday I wrote a tutorial about creating a CLRegion so that you can monitor when you enter or exit that particular area and have your app respond accordingly, even when the app is closed.
Today, I want to cover two more of the classes available in Core Location. Today we will focus on the CLGeocode class along with the CLPlacemark class. The reason I combine both in this tutorial, along with the required CLLocationManager and CLLocationManagerDelegate is that the CLGeocode class requires CLPlacemark to make it useful. Likewise, the CLPlacemark, according to documentation, is typically created by a CLGeocoder object. [Read more…]
When iOS 5 launched in October 2011, one of the features that caught my attention was location based reminders. Location based reminders provided the ability to connect a specific reminder to a specific location. An example could be, written in English, “When I arrive at the supermarket, remind me to buy flowers for my wife” or “when I leave work, remind me to call Fred”. When you approach a supermarket a reminder pops up telling you to go get flowers or when I leave the office, I get a reminder to call someone on my way home. Although GPS/location features have been available for most generations of the iPhone, mixing that power with context can make your app very powerful.
Of course, geofencing isn’t only for the built in reminders app that shipped with iOS 5. Apple has opened it up for developers to access. Today, we’ll be looking at how to work with geofencing which specifically uses the CLRegion Class as well as the CLLocationManager. A good place to start, as always, is the class reference. If you are unsure how to understand class references, methods, passing messages, properties etc… then take a read of this post and return back when done. [Read more…]
The NSUserDefaults Class allows you to save settings of your app so that when the user closes the app or perhaps reboots their iOS device, the settings you set are retained. A quick example could be a maps app that lets you set it to show distances in Miles or Kilometers.
Before I continue, I want to point out that if you want to share settings across devices then you need to look at storing preferences in iCloud.
In todays tutorial I want to show a quick demonstration of how NSUserDefaults works and how you create the object as well as save data. I will also show you how to retrieve the data so that your app can load up with the settings the user selected.
Various types of data can be stored in NSUserDefaults which includes NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. Typically you would wrap a UIImage in to NSData to store in NSUserDefaults. Of course, you can also use other options to store data such as CoreData, but NSUserDefaults is a quick and simple way to store small amounts of data with just a few lines of code.
Lets begin by creating a new Single View application in Xcode. We then need to add a few things to the storyboard. Although you can follow this tutorial step by step, perhaps you could also experiment with your own ideas. The storyboard below has two views. The standard View Controller on the left that is set up when you create a Single View App. The second is a Table View Controller. I chose a Table View Controller because this is how I typically see settings views arranged. Of course, it isn’t essential that you use a Table View Controller for a settings view.
iOS devices have several sensors built in that you can make use of in your app. One of them is the digital compass which is also known as a magnetometer. In todays tutorial I want to show you how how you can access the data so that you can use it in your app. The app will be very simple and will just use 8 UILabels with 4 of them being updated with various values.
To begin with, create a new project in Xcode and choose a Single View Application. If you are not sure how to do this, take a look at my post called Setting up your First iOS Xcode Project which will get you to a fresh start and ready to create the app.
The next step is to drag our 8 UILabels. Put four of them down the left side of the screen and the other four down the right side as pictured here (aligning the text on the right hand labels to the left). Change the names to something like seen in the screen shot. You do not have to set the right hand set at zeros… anything will do, including blank UILabels.
Next, click on the middle Editor button (top right) to create a split to allow two files to be opened. On the left, click the Storyboard. The ViewController header file should then appear on the right.
At the top of the header file, import CoreLocation and also add the CLLocationManagerDelegate as follows:
@interface ViewController : UIViewController <CLLocationManagerDelegate>
The first of these two lines indicates that we will be using some of the CoreLocation framework. The
A popular method used from the CLLocationManagerDelegate protocol is – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation which allows your app to receive updates when any location changes are detected. The new location details were stored in the newLocation which is a CLLocation.
When iOS 6 launched, that method was deprecated with a suggestion to use a newer version called – (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations or in short locationManager:didUpdateLocations:.
This quick tutorial has been created to explain how to handle a deprecated method, what should be done about it and where you can find out more details about the changes. If you want to know how to use the newer locationManager:didUpdateLocations: method then take a look at the didUpdateLocations tutorial that explains how to work with the NSArray provided by that method.
A quick tutorial today. I was recently asked how to get a timestamp from a CLLocation object, particularly when the -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations method was used in the CLLocationManagerDelegate protocol. As with most programming solutions, there’s always more than one way to accomplish this. Today, I’ll show you one of the ways it can be done.
Assuming you have your CLLocationManagerDelegate all configured correctly and that you also have your CLLocationManager, this is one way you can get the timestamp from the CLLocation update. [Read more…]
When iOS 6 launched last year, Apple deprecated a commonly used method from the CLLocationManagerDelegate protocol. The method deprecated is – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation and is used to tell the delegate that a new location is available. Each time a location change is detected, this method is called and within the method, you can trigger certain methods or updates to happen as needed.
This was done by using the (CLLocation *)newLocation details. With this method being deprecated in iOS 6, Apple recommends you now use a newer method called – (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations. Rather than providing a newLocation as a CLLocation, this new method returns an NSArray of locations. As the value is a different type, you will need to modify your code to account for the data being handed back in an NSArray.
The good news is that according to the documentation, you still get a CLLocation object, but instead of accessing it direct, you need to pull it out of the NSArray to action it. Lets take a look at some code that will help you do just that. [Read more…]
iOS developers get access to a number of frameworks to help them develop apps. One of the frameworks I like to use is Core Location, often joined with MapKit. The tutorial today will focus on just the Core Location framework and later in the series, we’ll add MapKit to the project so that you can mark your location on a map.
For the project, I’ll be developing for iOS 6 using Storyboards as well as ARC. So lets get going:
Creating the Project
First, lets create a new project by opening Xcode and clicking File > New > Project. I often opt for an empty application, but in this instance I’ll choose a Single View Application because this is all we need to demonstrate a way of working with Core Location.