ios Dev Fest Research Network Operations Center
Outline http://goo.gl/02blw Getting Started With App Development Setup Developer Environment Setup Certificates and Provisioning Deploying App To Device Real World App Development Example An end to end real world prototype
Setup Dev Environment https://developer.apple.com/devcenter/ios/index.action Pre-req: You must have registered an Apple ID Send registered Apple ID to devsupport@gatech.edu requesting to join the ios University Program Install Xcode From either: DMG downloaded from ios dev portal App Store
Developer Certificate After you receive an invite to join the ios University Account, you will need to request a developer certificate. Log into the provisioning portal: https:// developer.apple.com/ios/manage/overview/ index.action Click the certificate tab Click request certificate
Developer Certificate
Developer Certificate
Developer Certificate
Developer Certificate
Developer Certificate
Provisioning Profile Shortly after your developer certificate is approved, that certificate will be added to a provisioning profile for you to download and use. You should receive an email about when that is available. Log into the provisioning portal: https:// developer.apple.com/ios/manage/overview/index.action Click the provisioning tab Download the Wildcard Team Provisioning Profile
Certificate and Profile Install Double Click the Certificate and it will get added to your keychain. Double Click the provisioning profile and it will get added to Xcode Organizer
Certificate and Profile Install
Certificate and Profile Install
Deploying App To Device Device UDID needs to be added to the provisioning profile. For new devices, you need to send the UDID to devsupport@gatech.edu and it will be added to the provisioning profile. You will then need to re-download the provisioning profile replacing the previous one. The device needs to allow development, you click the Use for development button in Xcode Organizer on the desired device ios 6.1requires ios 6.1 SDK found in Xcode 4.6
Deploying App To Device
Deploying App To Device Load the Hello World Project Change the target from the simulator to device Click Run If everything is configured then it will run
Real World App Example For an end to end example in ios 6 there are some basic topics that we will need to cover Objective C Overview Storyboard Overview Comments App Walkthrough
Overview of Objective C GITMAD 2012
File Formats Extension Source Type.h Header files. Header files contain class, type, function, and constant declarations..m Source files. This is the typical extension used for source files and can contain both Objective-C and C code..mm Source files. A source file with this extension can contain C++ code in addition to Objective-C and C code. This extension should be used only if you actually refer to C++ classes or features from your Objective-C code.
Classes Classes allow for the basic encapsulation for some data and operations on that data. The interface portion is usually included in the.h portion. The implementation is usually in the.m file.
Example Class Declaration
Strong and Weak Types Strong typed variables include the class name in the declaration. Weakly typed variables use "id" instead. Why use one or the other? Example: MyClass *myobject1; //Strong Typing id myobject2; //Weak typing
Methods and Messaging There are 2 types of methods in Obj-C: instance methods and class methods An instance method is a method whose execution is scoped to a particular instance of the class. In other words, before you call an instance method, you must first create an instance of the class. Class methods, by comparison, do not require you to create an instance, but more on that later.
Method Declarations The minus sign indicates that this is an instance method. The method s actual name (insertobject:atindex:) is a concatenation of all of the signature keywords, including colon characters. The colon characters declare the presence of a parameter. If a method has no parameters, you omit the colon after the first (and only) signature keyword. In this example, the method takes two parameters.
Calling a Method When you call a method you do so by messaging the object. Example: [myarray insertobject:anobject atindex:0]; Inside the brackets, the object receiving the message is on the left side and the message is on the right.
Nested Messages To avoid declaring numerous local variables to store temporary results, Objective-C lets you nest messages. Example: [[myappobject thearray] insertobject:[myappobject objecttoinsert] atindex:0]; The return value from each nested message is used as a parameter, or as the target, of another message. For example, you could replace any of the variables used in the previous example with messages to retrieve the values.
Accessor methods Accessor methods get and set the state of an object, and typically take the form -(type)propertyname and -(void)setpropertyname: (type). Using dot syntax, you could rewrite the previous example as: Example: [myappobject.thearray insertobject: [myappobject objecttoinsert] atindex: 0]; You can also use dot syntax for assignment. myappobject.thearray = anewarray; This is the same as [myappobject setthearray:anewarray];
Class Implementations Like the class declaration, the class implementation is identified by two compiler directives here, @implementation and @ end. These directives provide the scoping information the compiler needs to associate the enclosed methods with the corresponding class.
Declared Properties Declared properties are a convenience notation used to replace the declaration and, optionally, implementation of accessor methods. Example: @property BOOL flag; @property (copy) NSString *nameobject; //Copy the object during assignment @property (readonly) UIView *rootview //Declare only a getter method. you can use the @synthesize compiler directive to ask the compiler to generate the methods according to the specification in the declaration: Example: @synthesize flag, nameobject, rootview; Properties reduce the amount of redundant code you have to write.
Strings Same as C. Single Quotes for single characters and Double quotes for strings. They don't typically use C-style strings. They pass strings around NSString objects. NSStrings are object wrappers that do most everything for you, including: built-in memory management for storing arbitrary-length strings, support for Unicode, printf-style formatting utilities just to name a few
Example Strings NSString *mystring = @"My String\n"; NSString *anotherstring = [NSString stringwithformat:@"%d %@", 1, @"String"]; //Create an Obj-C string from a C string NSString *fromcstring = [NSString stringwithcstring:"a C string" encoding: NSASCIIStringEncoding];
Protocols Declares methods that can be implemented by any class. They define an interface that other objects are responsible for implementing. When you implement the methods of a protocol in a class, your class is said to conform to that protocol. Protocols are frequently used to specify the interface for delegate objects. In the case of many delegate protocols, adopting a protocol is simply a matter of implementing the methods defined by that protocol.
Protocol Example @interface MyClass : NSObject <UIApplicationDelegate, AnotherProtocol> { } @end //Declaration of the protocol @protocol MyProtocol - (void)myprotocolmethod; @end
ios Storyboards http://www.slideshare.net/chriswynn2/ios-storyboards
This Talk What, When, Why and How? Demo
What? New feature in Xcode and ios Visual way to specify views and transitions between them
When? Xcode 4.2 ios Deployment Target: ios 5.0+ * Not supported for devices not running ios 5.0
Why? Reduces amount of glue code Bird s Eye view of your app
Sample Storyboard Image Courtesy: Ray Wenderlich http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
Advantages Single storyboard contains layout for ALL views/transitions (no separate nib files) Ctrl-drag to create a transition Flexible support for UITableViewCells Design directly in storyboard (no nib file)
How? New terminology Scene - view controller Segue - transition from one view to another Create a new project w/ Use Storyboard Create segues (ctrl-drag) in your Storyboard
How? (Optional) Add a behavior that occurs during (just before) a segue. Override method: -(void)prepareforsegue:(uistoryboardsegue *)segue sender: (id)sender { } if ([[segue identifier] isequaltostring:@ MySegue ]) { } SecondView *vc = [segue destinationviewcontroller]; /* set some data on the view controller */
How? (Optional #2) Programmatically invoke a segue: [self performseguewithidentifier:@ MySegue sender:self];
Demo
So what is UIStoryboard?
UIStoryboard is... Runtime representation of everything configured in Interface Builder
Can load any scene with: [UIStoryboard instantiateinitialviewcontroller]; [UIStoryboard instantiateviewcontrollerwithidentifier:@ myview ]; Can use multiple storyboards and load with: [UIStoryboard storyboardwithname:@ myboard bundle:mybundle];
Resources Tutorials: http://www.scott-sherwood.com/?p=219 http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1 WWDC 2011 Session Videos: Session 309 - Introducing Interface Builder Storyboarding
Comments App Walkthrough We will be creating a native version of a comments web app. For this we will use be using an adapted tutorial from http://www.scott-sherwood.com/ios-5- uistoryboards-a-practical-example/
Starting From Scratch Create a new Single View Application project in Xcode. Name it Comments and make sure you have Storyboard and ARC checked. The default Scene created when you create the project extends UIViewController and we want a UITableViewController for this application. The quickest way to do this is just to delete the default UIViewController class and scene, created a new UITableViewController class called GTTableViewController and pull on a new UITableView onto your Storyboard, creating a new scene, and set its class to GTTableViewController in the Identity Inspector.
Starting From Scratch To complete the scaffolding for this Xcode project create a Task class for representing your tasks. Create a constructor that can build an instance of the class from the dictionary returned from the web service. Also create a todictionary method to serialize the objected so that it can be posted to the web service.
Tying In The Storyboard From our previous setup we have a UITableViewController for displaying a list of tasks so an important feature will be for people to be able to add a task. So we will add a plus button to the initial scene in our storyboard so that we can support users in creating new tasks. To add this button we are going to embed the GTTableViewController in a UINavigationController by selecting the UITableViewController and going to the menu and selecting Editor->Embed In-> Navigation Controller. Then drag on a UIBarButtonItem on to the top right hand side of the navigation bar, in the attribute inspector change the identifier of the UIBarButtonItem to Add.