Archives for March 2013

Last updated by at .

iOS Programming Recipe 19: Using Core Motion to Access Gyro and Accelerometer

One of the coolest things smartphones are capable of now is the ability to sense motion and orientation. The iPhone does this with the use of a 3-axis Accelerometers and Gyroscopes. In this tutorial we’re going to create an app that indicates the current G and speed of rotation. Not exactly a pretty app but still instructional.

Assumptions

  • You have a developer account and have provisioned a device. Unfortunately we can’t simulate this stuff without hardware. Follow the Apple documentation here to get set up.
  • Make Sure you head over our Github page and download the source code. NSCookbook Github Recipe 19
  • You have looked over some of the past tutorials and are comfortable with creating outlets and actions from the interface builder

Setting Up the Interface

Our Interface will be pretty simple as we will be displaying 12 values. We’ll show Max and Current Acceleration and Rotation about the X,Y and Z axis’.

Start with a new single view project titled “GyrosAndAccelerometers” and make sure the storyboards are selected.

Once the new project is created, open up the storyboard and drag 25 Labels onto the view. Twelve of these labels will be our outlets that will display the output data for each axis. Rename the labels and add a button as shown in the image below:

[Read more…]

iOS Programming Recipe 18: Unit Testing With GHUnit & CocoaPods

This Recipe will cover using GHUnit to unit test the Weather Application we developed in Recipe 15: Building A Weather Application. GHUnit is an open source unit testing framework for Mac and iOS that (in my opinion) has capabilities superior to the unit testing capabilities built into Xcode. Many developers have there own philosophy on unit testing and this Recipe will not attempt to define another. We will not be defining unit testing best practices or even go into detail about writing particular tests. This Recipe is purely about getting started with GHUnit and how it can be used in the context of a real application. Oh and did I mention? GHUnit makes writing asynchronous unit tests a breeze!

Assumptions

  • This recipe uses the Weather Application created in Recipe 15: Building A Weather Application, it is highly recommended that you work through or at least familiarize yourself with that recipe before continuing on to this one.
  • Source code for the weather app can be downloaded via GitHub. The revision of the Weather App after Recipe 15 has been tagged recipe-15, make sure to start there.
  • This recipe also relies heavily on CocoaPods, it is recommended you watch NSScreencast’s video tutorial if you are not familiar with CocoaPods.

Getting Started

Download The Starting Application
  • First download the source code for our starting application, which happens to be the Weather App developed in Recipe 15.
  • Refer to Recipe 15¬†for details on setting up a Weather Underground developer account in order to obtain a personal API key. You will need this key in order to access Weather Underground’s services.
  • The Weather App was built using CocoaPods, so after getting the source code you will need to navigate to the project root directory (where the .xcodeproj file lives) and run the following command in terminal. Note this will not work if you have not yet installed CocoaPods, learn about doing so here.

1
$ pod install
  • This will add all of the necessary external dependencies the Weather App needs. It will also create an .xcworkspace file which you will need to open when accessing this project (not the .xcodeproj file).
  • Add your person API key for Weather Underground to WeatherAPIKey.h, then build & run the application. If everything has been done right you should now have a functioning weather application!

[Read more…]

iOS Programming Recipe 17: Using UISS To Theme Your Application

This Week I thought I would explore A nice iOS library which allows you to customize the look and feel of your application. While this library is built on UIAppearance, it extends it by introducing a CSS like way of defining the look and feel. We already had a recipe on UIAppearance, so we’ll start by creating the same thing and then explore customizations.

Assumptions

Setting Everything Up

Creating the Project

To get started we’ll need to create a new project and add the UISS library to it using cocoapods.

  • Create a new project and title it “Recipe17UsingUII”. Make sure to use ARC and select iPhone from the devices.

[Read more…]

iOS Programming Recipe 16: Populating A UITableView With Data From The Web

Since UITableView is so prominent in iOS apps, I felt it would be a good idea do one more useful recipe on the subject. For this Recipe we’ll be creating a UITableview complete with a detail view and a navigation controller. In addition, we’ll populate the table and the subsequent detail view with information retrieved from a web service. For this tutorial, we’ll be using the google places API to retrieve a list of restuarants in a city, display them in a tableview, and show more restaurant details in a detail view.

Assumptions

  • You have a grasp on Xcode Basics. If not, go get some education here.
  • I also recommend reading the other two tutorials on creating table Views as I’ll be building on some of the concepts in those tutorials.

Designing The Interface

To start off, we’re going to create a project using the Single View Application Template. Title the project “WebTableView”. On the storyboard, drag a new navigation controller into the scene. Control click from the prototype cell of the table view controller to the view controller and choose push from the segue type.
[Read more…]

css.php
Privacy Policy