IPhone App Internals: Difference between revisions
No edit summary |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
The application is a standard iPhone application, which makes use of the Core Location framework to gather location information and store it in an array. This array is then turned into a JSON object and uploaded. | The application is a standard iPhone application, which makes use of the Core Location framework to gather location information and store it in an array. This array is then turned into a JSON object and uploaded. | ||
The location information is stored as an array of CLLocation objects. The initial item in the array at index 0 is a NSDictionary used to store statistics about the commute as well as the status. This array is then stored inside another array, each item representing a different commute. | The user sets two points, where they work and where they live, and geofences are set around these areas. When the user leaves one, the application is notified and the location is recorded. When the user arrives at the other point, location updates are stopped. The location information is stored as an array of CLLocation objects. The initial item in the array at index 0 is a NSDictionary used to store statistics about the commute as well as the status. This array is then stored inside another array, each item representing a different commute. If an upload fails, the commute is stored and another attempt is made at uploading the commute at a later time. | ||
== Application Design == | ==Application Design== | ||
NB: the class prefix for all classes used in the application is 'CO2'. | |||
The overall UI design can be followed by looking through the Main.storyboard file. The <tt>RootViewController</tt> is the main View Controoler which is loaded on app startup. From here you can navigate to the settings view, (<tt>SettingsViewController</tt>) the about page which is just a normal <tt>ViewController</tt> and a view that shows all the recorded commutes on the device, <tt>MyCommutesViewController</tt>. This list is a UITableView populated on load from the array of stored commutes, and tapping a commute will load a <tt>CommuteMapViewController</tt> which will show the commute on a MapKit view. | |||
== API == | The AppDelegate is responsible for loading the main ViewController, and responds to system events such as detecting when the app is placed into the background, when it returns to the foreground etc. The AppDelegate creates an instance of <tt>LocationController</tt> when first opened, and this then manages the <tt>LocationRecorder</tt> object, creating it from scratch if no saved version exists, or loading the saved version from storage if it does. It is this object that contains the recorded commutes, as well as providing access to them. The <tt>LocationController</tt> also handles uploading the stored commutes, when this is started a background task is initiated that handles uploads. | ||
==Class List== | |||
* ''CCLocationController'' | |||
Class to control the recording of locations. When created, creates an instance of <tt>CO2LocationRecorder</tt> by restoring from disk or creating a new one if no previous data exists. The class is also a <tt>CLLocationManager</tt> and <tt>NSURLConnection</tt> delegate, as it is responsible for saving new location updates into a commute, and responding to remote servers when uploading the stored commutes. | |||
* ''CO2AppDelegate'' | |||
Controls initial app loading, initialising a <tt>CO2LocationController</tt> instance and setting up testing things such as TestFlight. | |||
* ''CO2CommuteMapViewController'' | |||
Displays a selected commute from <tt>CO2MyCommutesViewController</tt> by drawing a Polyline over an MKMapView. | |||
* ''CO2LocationRecorder'' | |||
Class responsible for recording commutes, managing and deriving statistics of recorded commutes. Allows commutes to be saved by saving and restoring this object to disk, a task managed by <tt>CO2LocationController</tt> instances. | |||
* ''CO2MapViewController'' | |||
Controls the view for editing home and work locations, by receiving long press events on an MKMapView. | |||
* ''CO2MyCommutesViewController'' | |||
Supllies the view for listing all commutes currently stored on the drive and / or in progress. Contains a Table View which uses <tt>CO2CommuteCell</tt> as the prototype cell. | |||
* ''CO2RootViewController'' | |||
The main view controller for the app, which controls the view that is loaded on app launch. | |||
* ''CO2SettingsViewController'' | |||
View controller for the settings view, which controls locker authentication details, calculating the storage space currently used for recording commutes as well as providing the option for manually triggering uploads. | |||
* ''CO2CommuteCell'' | |||
A class to define the custom cell used to display commutes within the commute list. | |||
==API== | |||
The app will communicate with any endpoint configured to accept [http://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] requests, and will attempt to send a [http://www.json.org/ JSON] array representation of the commute data to the URL specified in the app's settings. The user name and password are used to authenticate to the remote server using [http://en.wikipedia.org/wiki/Basic_access_authentication HTTP Basic Access Authentication.] | The app will communicate with any endpoint configured to accept [http://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] requests, and will attempt to send a [http://www.json.org/ JSON] array representation of the commute data to the URL specified in the app's settings. The user name and password are used to authenticate to the remote server using [http://en.wikipedia.org/wiki/Basic_access_authentication HTTP Basic Access Authentication.] | ||
When working with a locker it uses the push endpoints which allows the push of any JSON object. For more information on this see [[ | When working with a locker it uses the push endpoints which allows the push of any JSON object. For more information on this see [[Building_Locker_Apps#Locker_Push_API|Locker Push API]] |
Latest revision as of 10:28, 19 February 2013
Overview
The application is a standard iPhone application, which makes use of the Core Location framework to gather location information and store it in an array. This array is then turned into a JSON object and uploaded.
The user sets two points, where they work and where they live, and geofences are set around these areas. When the user leaves one, the application is notified and the location is recorded. When the user arrives at the other point, location updates are stopped. The location information is stored as an array of CLLocation objects. The initial item in the array at index 0 is a NSDictionary used to store statistics about the commute as well as the status. This array is then stored inside another array, each item representing a different commute. If an upload fails, the commute is stored and another attempt is made at uploading the commute at a later time.
Application Design
NB: the class prefix for all classes used in the application is 'CO2'.
The overall UI design can be followed by looking through the Main.storyboard file. The RootViewController is the main View Controoler which is loaded on app startup. From here you can navigate to the settings view, (SettingsViewController) the about page which is just a normal ViewController and a view that shows all the recorded commutes on the device, MyCommutesViewController. This list is a UITableView populated on load from the array of stored commutes, and tapping a commute will load a CommuteMapViewController which will show the commute on a MapKit view.
The AppDelegate is responsible for loading the main ViewController, and responds to system events such as detecting when the app is placed into the background, when it returns to the foreground etc. The AppDelegate creates an instance of LocationController when first opened, and this then manages the LocationRecorder object, creating it from scratch if no saved version exists, or loading the saved version from storage if it does. It is this object that contains the recorded commutes, as well as providing access to them. The LocationController also handles uploading the stored commutes, when this is started a background task is initiated that handles uploads.
Class List
- CCLocationController
Class to control the recording of locations. When created, creates an instance of CO2LocationRecorder by restoring from disk or creating a new one if no previous data exists. The class is also a CLLocationManager and NSURLConnection delegate, as it is responsible for saving new location updates into a commute, and responding to remote servers when uploading the stored commutes.
- CO2AppDelegate
Controls initial app loading, initialising a CO2LocationController instance and setting up testing things such as TestFlight.
- CO2CommuteMapViewController
Displays a selected commute from CO2MyCommutesViewController by drawing a Polyline over an MKMapView.
- CO2LocationRecorder
Class responsible for recording commutes, managing and deriving statistics of recorded commutes. Allows commutes to be saved by saving and restoring this object to disk, a task managed by CO2LocationController instances.
- CO2MapViewController
Controls the view for editing home and work locations, by receiving long press events on an MKMapView.
- CO2MyCommutesViewController
Supllies the view for listing all commutes currently stored on the drive and / or in progress. Contains a Table View which uses CO2CommuteCell as the prototype cell.
- CO2RootViewController
The main view controller for the app, which controls the view that is loaded on app launch.
- CO2SettingsViewController
View controller for the settings view, which controls locker authentication details, calculating the storage space currently used for recording commutes as well as providing the option for manually triggering uploads.
- CO2CommuteCell
A class to define the custom cell used to display commutes within the commute list.
API
The app will communicate with any endpoint configured to accept HTTP POST requests, and will attempt to send a JSON array representation of the commute data to the URL specified in the app's settings. The user name and password are used to authenticate to the remote server using HTTP Basic Access Authentication.
When working with a locker it uses the push endpoints which allows the push of any JSON object. For more information on this see Locker Push API