iOS Tutorial Christopher M. Judd
Wednesday, October 23, 13
Christopher M. Judd CTO and Partner at leader Columbus
Wednesday, October 23, 13
Developer User Group (CIDUG)
Wednesday, October 23, 13
Your mobile phone has more computing power than all of NASA in 1969. NASA launched a man to the moon.
Wednesday, October 23, 13
We launch a bird into pigs. twitter
Wednesday, October 23, 13
Current tutorial stuff
http://juddsolutions.com/ios_tutorial/ Wednesday, October 23, 13
Wednesday, October 23, 13
iOS Developer Programs Developer Free Can not deploy to a device Standard Program $99/year Deploy to up to 100 Ad Hoc devices Deploy to App Store Enterprise Program $299/year For developing internal application and deploying to company phones
Wednesday, October 23, 13
What you need
Mac Mac OS X 10.7.x (Mountain Lion) Xcode 5 > iPhone, iPod Touch and/or iPad $99/year Join Standard Program http://developer.apple.com/ios To learn Objective-C Wednesday, October 23, 13
http://developer.apple.com/ios/ Wednesday, October 23, 13
Register as an organization instead of individual
Organizations can have team members
Otherwise everyone has to be super admin
Wednesday, October 23, 13
Watch Wednesday, October 23, 13
Free
http://developer.apple.com/ios/ Mac App Store
Wednesday, October 23, 13
Xcode IDE Interface Builder
Simulator iPhone Simulator Wednesday, October 23, 13
Instruments Profiler
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
Learn the Basics
Wednesday, October 23, 13
Embedded Browser
Wednesday, October 23, 13
Starting Project
Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
Create new project
Wednesday, October 23, 13
or File > New Project... or ⇧⌘N
Choose project template
Wednesday, October 23, 13
Application Templates
Master-Detail (Contacts)
OpenGL
Page-Based
Single View (Camera)
Utility (Stock)
Empty
SpriteKit Game
(Core Data)
Tabbed (Music)
(Core Data) Wednesday, October 23, 13
(Core Data)
Wednesday, October 23, 13
version control Wednesday, October 23, 13
Wednesday, October 23, 13
Running
Select simulator or device
Run
or ⌘R Wednesday, October 23, 13
iPhone & iPad Simulator
Wednesday, October 23, 13
<project name>.xcodeproj is really a directory and what is opened by Xcode
<project name>.xcodeproj/xcuserdata/ directory containing user preferences this directory is not usually version controlled
Wednesday, October 23, 13
Lab 1
1. Create a MyBrowser project with Git support for both iPhone and iPad 2. Run the application in the simulator
Wednesday, October 23, 13
Laying it All Out
Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
iPhone Storyboard
Wednesday, October 23, 13
Text Field Placeholder: URL Keyboard: URL
Button Title: Go
Web View
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Top Space to Top Layout Guide
Leading space to container
Trailing space to container
Bottom Space to Bottom Layout Guide Wednesday, October 23, 13
Wednesday, October 23, 13
Why’s the iPad blank?
Wednesday, October 23, 13
iPad Storyboard
Wednesday, October 23, 13
Lab 2
1. Layout iPhone version of browser by adding Text Field and Web View 2. Layout iPad version of browser by adding Text Field and Web View 3. Run the application in the simulator 4. Experiment with some of the properties 5. Layout landscape
Wednesday, October 23, 13
Objective-C Primer
Wednesday, October 23, 13
Classes MyClass.h
Class name
Parent class name
#import @interface MyClass : NSObject { int count; NSString* name; // String typing id data; // Weak typing }
Member variable declaration (ivars)
- (id)initWithString:(NSString*)aName; + (MyClass*)createMyClassWithString:(NSString*) aName; @end
MyClass.m #import "MyClass.h" @interface MyClass () @end @implementation MyClass { NSString* privateName; } - (id)initWithString:(NSString *)aName { self = [super init]; if (self) { name = [aName copy]; } return self; } + (MyClass *)createMyClassWithString: (NSString *)aName { return [[self alloc] initWithString:aName]; } @end
allocate memory Wednesday, October 23, 13
constructor call
Instance method (constructor) Class method (factory method)
Methods and Messaging Method Declaration Syntax method signature
method type
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index return type parameter types
parameter names
Messaging Syntax param values
[myArray insertObject:anObject atIndex:0]; receiver
selector/keyword message
Wednesday, October 23, 13
Properties and Synthesize MyClass.h #import @interface MyClass : NSObject { } // use of @property declaration for the title variable is equivalent to // declaring a “setTitle” mutator and “title” accessor method. @property (weak, nonatomic) NSString* title; @end MyClass.m #import "MyClass.h" @interface MyClass () @property (weak, nonatomic) NSString* privateTitle; @end @implementation MyClass // use the @synthesize declaration in the .m implementation file // to automatically implement setter and getter methods. @synthesize title; @synthesize privateTitle; @end Wednesday, October 23, 13
Property Usage
myClass.title = @"title" id title = myClass.title
Wednesday, October 23, 13
=
[myClass setTitle: @"title"] id title = [myClass title]
Protocols/Delegates implements protocol *ViewController.h #import @interface JSBViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *urlField; @property (weak, nonatomic) IBOutlet UIWebView *webView; - (IBAction)browseTo:(id)sender; @end
*ViewController.m
implement required and/or optional methods
#import "JSBViewController.h" @implementation JSBViewController @synthesize urlField; @synthesize webView; - (BOOL)textFieldShouldReturn:(UITextField *)textField { [self browseTo:textField]; return YES; } // removed code for brevity @end Wednesday, October 23, 13
Blocks
Use NSArray *cards = [NSArray arrayWithObjects:@"Jack", @"Queen", @"King", @"Ace", nil]; [cards enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) { NSLog(@"%@ card at index %d", object, index); }];
Declaration - (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
Wednesday, October 23, 13
www.dzone.com
Get More Refcardz! Visit refcardz.com
#110
Objective-C
CONTENTS INCLUDE: An Introduction to the Language and Tools The Syntax Memory Management Tools Debugging XCode Keyboard Shortcuts and more...
for the iPhone and iPad By Ben Ellingson and Matthew McCullough
AN INTRODUCTION TO THE LANGUAGE AND TOOLS
Hot Tip
Objective-C is the primary language used to create applications for Apple’s Mac OS X and iOS (iPhone and iPad) platforms. Objective-C was created by Brad Cox and Tom Love in the early 1980s. In 1988, Objective-C was licensed by NeXT, a company founded and helmed by Steve Jobs during his absence from Apple. Apple acquired NeXT in 1996, bringing Objective-C to the Macintosh platform.
Interfaces Objective-C interfaces are created using the @protocol declaration. Any class can implement multiple interfaces. Interfaces are typically declared in a .h header file and can be included via #import statements in the .h header file of other classes.
Objective-C is an object oriented superset of ANSI C. Its object syntax is derived from Smalltalk. It supports single inheritance, implementation of multiple interfaces via the @protocol syntax, and the redefinition and augmentation of (open) classes via categories. Apple’s iPhone SDK for the iOS mobile operating system offers developers a rich set of Objective-C APIs. This free SDK, which includes the Xcode IDE, is used to create applications for the iPhone, iPad, and iPod Touch.
// Mappable.h: Declare the Mappable @protocol @protocol Mappable - (double) latitude; - (double) longitude; @end // Location.h: Specify that Location class implements the Mappable // @protocol #import “Mappable.h” @interface Location : NSObject <Mappable> { } @end
THE SYNTAX
// Location.m: Provide implementations for the Mappable methods @implementation Location - (double) latitude { return 46.553666; } - (double) longitude { return -87.40551; } @end
Class Declaration Objective-C classes typically include an interface .h and an implementation .m pair of files. The .h file contains property and method declarations. The .m file contains method implementations.
Objective-C for the iPhone and iPad
The keyword @interface can distract developers coming from some languages such as Java, suggesting this is a mere contract. However, @interface is indeed the keyword for defining the properties and method signatures of a concrete class in Obj-C.
Primitive Data Types As a superset of ANSI C, Objective-C supports its same primitive data types.
Example .h interface file #import @interface Speaker : NSObject { NSInteger *ID; NSString *name; } @property NSInteger *ID; @property(nonatomic,retain) NSString *name; - (void) doSomething: (NSString *) value anotherValue: (int) value2; @end
int
Integral numbers without decimal points
float
Numbers with decimal points
Example .m implementation file
Get over 90 DZone Refcardz FREE from Refcardz.com!
#import “Speaker.h” @implementation Speaker @synthesize ID,name; - (void) doSomething: (NSString *) value anotherValue: (int) value2 { // do something } @end
Inheritance Class inheritance is specified in the .h interface file with the syntax: @interface <MyClass> : <ParentClass>. The following example tells the compiler that the Employee class inherits from (extends) the Person class. @interface Employee : Person { } @end
DZone, Inc.
|
www.dzone.com
http://refcardz.dzone.com/refcardz/objective-c-iphone-and-ipad Wednesday, October 23, 13
http://developer.apple.com/library/mac/documentation/cocoa/conceptual/objectivec/objc.pdf Wednesday, October 23, 13
Coding it Up
Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
Add Outlets
Wednesday, October 23, 13
Add Actions
Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
*ViewController.m #import "JSENViewController.h" @interface JSENViewController () @property (weak, nonatomic) IBOutlet UITextField *urlField; @property (weak, nonatomic) IBOutlet UIWebView *webView; @end @implementation JSENViewController @synthesize urlField; @synthesize webView;
outlets
actions
- (IBAction)browseTo:(id)sender { // hide keyboard [urlField resignFirstResponder]; NSURL *url = [[NSURL alloc] initWithString:urlField.text]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url]; [webView loadRequest:request]; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewDidUnload { [self setUrlField:nil]; [self setWebView:nil]; [super viewDidUnload]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; } } @end
Wednesday, October 23, 13
doesn’t work
Wednesday, October 23, 13
*ViewController.h #import @interface JSENViewController : UIViewController @end *ViewController.m #import "JSENViewController.h"
implement protocol
@implementation JSENViewController @synthesize urlField; @synthesize webView; - (IBAction)browseTo:(id)sender { // some code removed for brevity }
implement protocol method
- (BOOL)textFieldShouldReturn:(UITextField *)textField { [self browseTo:textField]; return YES; } - (void)viewDidLoad { [super viewDidLoad]; urlField.delegate = self; } // some code removed for brevity @end Wednesday, October 23, 13
assign delegate
Lab 3
1. Add Text Field and WebView outlets 2. Add browseTo action 3. Add UITextField delegate 4. Run the application in the simulator
Wednesday, October 23, 13
Making it Fancy
Wednesday, October 23, 13
App Icon
Wednesday, October 23, 13
App Icons
Icon.png iPhone 57x57 Wednesday, October 23, 13
Icon-72.png iPad 72x72
[email protected] iPhone Retina 114x114
[email protected] iPhone Retina 144x144
Default App Icon
flat image
rounded & shine Wednesday, October 23, 13
No Shine Info.plist
Wednesday, October 23, 13
Required and optional icons Image Size (px)
Filename
Used For
Required Status
512 x 512
iTunesArtwork.png
App icon for the App Store
Required
1024 x 1024
[email protected] App icon for the App Store
Optional but recommended
57 x 57
Icon.png
Home screen on iPhone/iPod touch
Required
114 x 114
[email protected] Home Screen on iPhone/iPod touch Retina
Required
72 x 72
Icon-72.png
Home screen on iPad
Required
144 x 144
[email protected] Home screen on iPad Retina
Required
29 x 29
Icon-Small.png
Spotlight and Settings for iPhone
Optional but recommended
50 x 50
Icon-Small-50.png
Spotlight and Settings for iPad
Optional but recommended
58 x 58
[email protected] Spotlight and Settings for iPhone Retina
Optional but recommended
100 x 100
[email protected] Spotlight and Settings for iPad Retina
Optional but recommended
.png
Wednesday, October 23, 13
Launch Image/Splash screen
Device
Portrait
Filename
Landscape
Filename
iPhone and iPod touch
320 x 480 pixels
Default~iphone.png
Not supported
Not supported
iPhone and iPod touch Retina
640 x 960 pixels
Default@2x~iphone.png
Not supported
Not supported
iPad
768 x 1004 pixels
Default-Portrait~ipad.png
1024 x 748 pixels
Default-Landscape~ipad.png
iPad Retina
1536 x 2008 pixels
Default-Portrait@2x~ipad.png
2048 x 1496 pixels
Default-Landscape@2x~ipad.png
<scale_modifier><device_modifier>.png Wednesday, October 23, 13
Launch Image
Apple’s recommendation is the first screen to make it look like it loads faster Wednesday, October 23, 13
Lab 4
1. Add iPhone and iPad app icons 2. Add iPhone and iPad launch image 3. Run the application in the simulator
note: use images in the iOS Tutorial Resources.zip file Wednesday, October 23, 13
Profile
Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
Analyze
Wednesday, October 23, 13
Product > Analyze
results
Wednesday, October 23, 13
Instruments
Wednesday, October 23, 13
Product > Profile
Wednesday, October 23, 13
Wednesday, October 23, 13
Simulator
Wednesday, October 23, 13
Device
Lab 5
1. Analyze application 2. Profile application with Instruments
Wednesday, October 23, 13
Deploy
Wednesday, October 23, 13
$ Wednesday, October 23, 13
1.Create project 2.Design interface 3.Wire up outlets and actions 4.Implement actions 5.Run application 6.Profile application 7.Deploy the application Wednesday, October 23, 13
Development (device) Ad Hoc App Store
Wednesday, October 23, 13
Deploying to Device
Wednesday, October 23, 13
must be a registered developer
Wednesday, October 23, 13
https://developer.apple.com/ios Wednesday, October 23, 13
Team Management
Wednesday, October 23, 13
as admin user
Wednesday, October 23, 13
admin may register team members
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Roles
Agent = Super Admin Wednesday, October 23, 13
Wednesday, October 23, 13
As Developer
Wednesday, October 23, 13
Wednesday, October 23, 13
same registration process again
Wednesday, October 23, 13
Wednesday, October 23, 13
must have a provisioning profile
Wednesday, October 23, 13
Wednesday, October 23, 13
As Developer
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
As Admin approve signing request
Wednesday, October 23, 13
As Developer download certificate
Wednesday, October 23, 13
As Developer email admin UDID
Wednesday, October 23, 13
As Admin add device
Wednesday, October 23, 13
Wednesday, October 23, 13
As Developer download profile
Wednesday, October 23, 13
Wednesday, October 23, 13
Running device Run
or ⌘R Wednesday, October 23, 13
Lab 6
1. Deploy to local device
Wednesday, October 23, 13
Ad hoc Deployment
Wednesday, October 23, 13
Wednesday, October 23, 13
Distribution Certificates
Wednesday, October 23, 13
UDID
Wednesday, October 23, 13
As Admin add device
Wednesday, October 23, 13
App IDs
Wednesday, October 23, 13
Ad Hoc Store Provisioning Profile
Wednesday, October 23, 13
Archive Product > Archive
Wednesday, October 23, 13
Email to Beta Testers
Wednesday, October 23, 13
Tools & Services to simplify Ad Hoc Deployment Wednesday, October 23, 13
https://testflightapp.com
Free Wednesday, October 23, 13
http://hockeykit.net/
Wednesday, October 23, 13
Open Source
http://www.hockeyapp.net/
Wednesday, October 23, 13
https://appblade.com/
• mobile device management • cross platform deployment • security Wednesday, October 23, 13
http://www.appsendr.com/
Wednesday, October 23, 13
App Store Deployment
Wednesday, October 23, 13
Wednesday, October 23, 13
App Store Provisioning Profile
Wednesday, October 23, 13
Submit to App Store
Wednesday, October 23, 13
Submit to App Store
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Wednesday, October 23, 13
Screenshots
Wednesday, October 23, 13
Screenshots
Press and Hold
Wednesday, October 23, 13
Screenshots
http://www.curioustimes.de/iphonesimulatorcropper/ Wednesday, October 23, 13
Wednesday, October 23, 13
https://developer.apple.com/appstore/guidelines.html
Wednesday, October 23, 13
wait for approval
Wednesday, October 23, 13
http://reviewtimes.shinydevelopment.com/ Wednesday, October 23, 13
Wednesday, October 23, 13
$ Wednesday, October 23, 13
glossed over Paid apps iCloud Game Center In-App Purchase Push Notifications
Wednesday, October 23, 13
Analytics Apple
Downloads
Wednesday, October 23, 13
Analytic Companies
Uses New Users Device Types Locations Events
Resources
Wednesday, October 23, 13
Christopher M. Judd CTO and Partner email:
[email protected] web: www.juddsolutions.com blog: juddsolutions.blogspot.com twitter: javajudd
Wednesday, October 23, 13