Beginning iOS Development

Course No. 10-152-143

Chapter 4 — Delegation and Core Location (iOS)

Follow the book for the content of the project. Use Modern Objective C wherever possible.

Project, Targets, and Frameworks

  • A project is just a list of files in a project.
    • What’s a project, really?

    • What is the Whereami.xcodeproj file?
    • Control-click on the Whereami.xcodeproj file and select Show Package Contents.

    • This is what an .xcodeproj file really is. It’s a directory that holds information about your project.

  • A target uses the files to make a product, which is an app in our case.

  • It lists the files and resources needed to build your app.

  • Adding the CoreLocation.framework.
    • Click on the + below the list of other frameworks

    • Scroll down a bit, click on CoreLocation.framework and press the Add button.

Core Location

  • Put this in the WhereamiViewController.h file.
  • Add this property to the class extension in the WhereamiViewController.m file. Don’t use the instance variable in the book.
  • Use this version of the initWithNibName:bundle:
  • This will give us a nasty looking warning!

Receiving updates from CLLocationManager

  • Huh! What a coincidence that the book uses us for its location example.

  • Now we need to implement methods that are part of the delegate protocol. The book says to start with the following method.
  • However, if you look in the documentation at the protocol methods you will see this.

  • The method has been deprecated in iOS 6.0. Should we still use it? No! Apple will removed deprecated methods eventually. You should get into the habit of never implementing them in new code.
  • How do we figure out what method to use? Just click on the method link and you will see this.

  • We should use locationManager:didUpdateLocations: instead. Let’s look at how that works. Here’s its documentation.
  • Notice the last line above.
    • “Therefore, the most recent location update is at the end of the array.”
  • To use the most recent location from this method we will need to access the last one in the array. Here’s the new method we need to implement.
  • And, finally, add this method.
  • Run the app! First you’ll get this.

  • Press OK and you’ll start getting data in the console.
  • So, how about that wicked warning. We solve it with something you’ve heard about before, delegation.
  • Add this protocol to the @interface declaration for you class.


  • The CLLocationManager has a lot of methods. Here are its methods.
  • Tasks
  • Accessing the Delegate
    •   delegate property
  • Determining the Availability of Services
    • + authorizationStatus
    • + locationServicesEnabled
    • + deferredLocationUpdatesAvailable
    • + significantLocationChangeMonitoringAvailable
    • + headingAvailable
    • + regionMonitoringAvailable
  • Initiating Standard Location Updates
    • – startUpdatingLocation
    • – stopUpdatingLocation
    •   pausesLocationUpdatesAutomatically property
    •   distanceFilter property
    •   desiredAccuracy property
    •   activityType property
  • Initiating Significant Location Updates
    • – startMonitoringSignificantLocationChanges
    • – stopMonitoringSignificantLocationChanges
  • Initiating Heading Updates
    • – startUpdatingHeading
    • – stopUpdatingHeading
    • – dismissHeadingCalibrationDisplay
    •   headingFilter property
    •   headingOrientation property
  • Initiating Region Monitoring
    • – startMonitoringForRegion:
    • – stopMonitoringForRegion:
    •   monitoredRegions property
    •   maximumRegionMonitoringDistance property
  • Deferring Location Updates
    • – allowDeferredLocationUpdatesUntilTraveled:timeout:
    • – disallowDeferredLocationUpdates
  • Getting Recently Retrieved Data
    •   location property
    •   heading property
  • Describing Your Application’s Services to the User
    •   purpose property Deprecated in iOS 4.0
  • Deprecated Properties and Methods
    • + regionMonitoringEnabled Deprecated in iOS 4.0
    • – startMonitoringForRegion:desiredAccuracy: Deprecated in iOS 4.0
    •   headingAvailable property Deprecated in iOS 4.0
    •   locationServicesEnabled property Deprecated in iOS 4.0
  • Tasks
  • Responding to Location Events
    • – locationManager:didUpdateLocations:
    • – locationManager:didFailWithError:
    • – locationManager:didFinishDeferredUpdatesWithError:
    • – locationManager:didUpdateToLocation:fromLocation: Deprecated in iOS 6.0
  • Pausing Location Updates
    • – locationManagerDidPauseLocationUpdates:
    • – locationManagerDidResumeLocationUpdates:
  • Responding to Heading Events
    • – locationManager:didUpdateHeading:
    • – locationManagerShouldDisplayHeadingCalibration:
  • Responding to Region Events
    • – locationManager:didEnterRegion:
    • – locationManager:didExitRegion:
    • – locationManager:monitoringDidFailForRegion:withError:
    • – locationManager:didStartMonitoringForRegion:
  • Responding to Authorization Changes
    • – locationManager:didChangeAuthorizationStatus:


Using the Debugger

Diagnosing crashes and exceptions

For the More Curious: Build Phases, Compiler Errors, and Linker Errors