SlideShare une entreprise Scribd logo
1  sur  86
Programming with iPhone SDK
                                                                         Xcode 3.2.4 - iOS 4.1




                                                                           Javier González Sánchez
                                                                    Maria Elena Chávez Echeagaray


Copyright is held by the author/owner(s).
SPLASH 2010, October 17-21, 2010. Reno, Nevada, USA
Personal Profiles
Schedule
Introduction
           1.
iOS Devices

Screen size. iPhone 4 960 x 640 pixels and
iPad 1024 x 768 pixels.

Light mobiles. iPod (3.56 oz), iPad (1.6 lb),
iPhone (4.8 oz).


Yesterday one application at a time. Today
multitasking.

Only one window. iPhone applications only
can have one window at a time.

Five seconds limit. When the user hits the
home button, your application will have 5
seconds to save data, close and give up its
control. If it takes more than that, it will be
terminated.
                                                                5
iOS Devices

CPU. Apple A4 ≈ 1 GHz.
Memory administration. iPod & iPad (256
MB), iPhone (512 MB) of RAM. Without a
“garbage collector”.
Storage. iPod (8, 32 & 64 GB), iPad(16-64
GB), iPhone (16-32 GB).
File Management. It provides each
application with a sandbox (2GB), where the
apps can read/write files and store data.

Multitouch user interface.

Other features. iPhone includes Core
Location, built-in camera and photo library, a
built-in accelerometer, digital compass,
proximity sensor, and ambient light sensor.
And a Phone with WiFi.
                                                               6
iOS SDK
      2.
iOS Developer Program




                    8
iOS Developer Program

  There is a free SDK that allows you to create your applications, and test
  them in a Simulator on your Mac. Ok!, so what?, Is this a business?

  There is a Individual/Company program or the Enterprise program. They cost
  $99 and $299 (annual) respectively. There is also the option of the University
  program for free. Once you sign into any program you can upload your
  applications to your device (iPod, iPad, iPhone) or distribute them through
  the App Store.

  They take care of the process (30% revenue), you can take then care of your
  development.

  September 2009 = 85,000 apps in the Apple Store, September 2010 =
  250,000 apps.

  September 2009 = 2K millions downloads in the Apple Store, September
  2010 = 6.5 millions downloads.
                                                                                   9
Installation
iOS SDK


                •  Sample code
Documentation   •  Reference libraries
                •  Coding how-to

                •  UIKit
                •  Foundation
 Frameworks     •  OpenGL / Quartz / Core Graphics
                •  Media


                •  Xcode,
    Tools       •  Interface Builder
                •  iOS Simulator




                                                           11
Frameworks

                  Foundation
Cocoa Touch
                  UIKit
                  OpenGL ES, Quartz,
   Media
                  OpenAL, Core Audio,
                  Core Animation
                  Core Location,
Core Services
                  CFNetwork,
                  SQLite | Core Data
                  Security,

                  UNIX sockets
  Core OS
                  File system
                  Memory allocation     12
Tools

We will be working with:


    Xcode. Apple's Integrated Development Environment (IDE).

    Interface Builder (IB). Environment to facilitate the development of your GUI's
    and to give functionality to its components.

    iPhone Simulator. It allows you to run your applications on your Mac.
    NOTE: iOS SDK does not allow you to upload your applications to your device
    (iPod / iPad / iPhone) or distribute them in the App Store.

    Instruments. Environment which lets you analyze the performance of your
    applications while running in the simulator or on a device.




                                                                                       13
Xcode




    14
Interface Builder
  Library
                                 View

               .xib file

                                 View




                                Design area
GUI elements                                  15
Interface Builder

  Interface Builder is the tool you use to assemble your application’s user
  interface visually.


  After you’ve placed the components on the window’s surface, you can
  establish the relationships between those components and your code.
  When your interface looks the way you want it, you save the contents
  to a nib file, which is a custom resource file format.


  The nib files you create in Interface Builder contain all the information
  that the UI Kit needs to recreate the same objects in your application at
  runtime. Loading a nib file creates runtime versions of all the objects
  stored in the file, configuring them exactly as they were in Interface
  Builder.

                                                                               16
Coding


 Hello Splash
Model (delegate) + View + Controller



                        View
                               Include
                               XIB files




            Model                          Controller

Delegates




                                                        18
Objective-C
          3.
Objective-C

  Is a simple computer language designed to enable sophisticated OO programming.


  Extends the standard ANSI C language by providing syntax for defining classes,
  methods, and properties, as well as other constructs that promote dynamic
  extension of classes.



  Based mostly on Smalltalk (class syntax and design), one of the first object-oriented
  programming languages.



  Includes the traditional object-oriented concepts, such as encapsulation,
  inheritance, and polymorphism.



                                                                                       20
Files


     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 could 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.




                                                                                      21
#import

  To include header files in your source code, you can use the standard #include, but….
  Objective-C provides a better way: #import. it makes sure that the same file is never
  included more than once.


 	
  #import	
  “MyAppDelegate.h”	
  
 	
  #import	
  “MyViewController.h”	
  

 	
  #import	
  <UIKit/UIKit.h>	
  




                                                                                           22
Class

  The specification of a class in Objective-C requires two distinct pieces: the
  interface (.h files) and the implementation (.m files).

  The interface portion contains the class declaration and defines the instance
  variables and methods associated with the class.
     @interface	
  
 	
  …	
  
 	
  @end	
  



  The implementation portion contains the actual code for the methods of the
  class.
 	
  @implementation	
  
 	
  …	
  
 	
  @end	
  



                                                                                   23
Class
                                             Class name
@interface	
  MyClass	
  :	
  NSObject	
                Parent class
{	
  
           	
  int	
  count;	
  
           	
  id	
  data;	
                                        Instance variables
           	
  NSString*	
  name;	
  
}	
  

-­‐	
  (id)initWithString:(NSString	
  *)aName;	
  
                                                                                methods
+	
  (MyClass	
  *)createMyClassWithString:	
  (NSString	
  *)	
  aName;	
  

@end	
  




                                                                                         24
Class

@implementation	
  MyClass	
  
                                                                    Class name

-­‐	
  (id)initWithString:(NSString	
  *)	
  aName	
  
{	
  
	
  	
  	
  	
  if	
  (self	
  =	
  [super	
  init])	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  count	
  =	
  0;	
  
	
  	
  	
  	
  	
  	
  	
  	
  data	
  =	
  nil;	
                                         methods
	
  	
  	
  	
  	
  	
  	
  	
  name	
  =	
  [aName	
  copy];	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  self;	
  
	
  	
  	
  	
  }	
  
}	
  

+	
  (MyClass	
  *)createMyClassWithString:	
  (NSString	
  *)	
  aName	
  
{	
  
	
  	
  	
  	
  return	
  [[[self	
  alloc]	
  initWithString:aName]	
  autorelease];	
  
}	
  

@end	
  


                                                                                                 25
Methods

  A class in Objective-C can declare two types of methods:
  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.



 Method type identifier             One or more signature keywords


 	
  -­‐(void)insertObject:(id)anObject	
  atIndex:(NSUInteger)index;	
  




           Return type                       Parameters with (type) and name
                                                                                         26
Methods

So	
  the	
  declaration	
  of	
  the	
  method	
  insertObject	
  would	
  be:	
  

-­‐(void)insertObject:(id)anObject	
  atIndex:(NSUInteger)index	
  



     Method type identifier, is (-) to instance methods, (+) to class methods.




And	
  the	
  line	
  to	
  call	
  the	
  method	
  would	
  be:	
  

[myArray	
  insertObject:anObj	
  atIndex:0];	
  



                                                                                            27
Properties

  They are simply a shorthand for defining methods (getters and setters) that
  access existing instance variables.



  Properties do not create new instance variables in your class declaration.


  Reduce the amount of redundant code you have to writ, because most
  accessor methods are implemented in similar ways.



  You specify the behavior you want using the property declaration and then
  synthesize actual getter and setter methods based on that declaration at
  compile time.

                                                                                 28
Properties

In the interface we have:
{	
  
BOOL	
  flag;	
  
NSString*	
  myObject;	
  
UIView*	
  rootView;	
  
}	
  

@property	
  BOOL	
  flag;	
  
@property	
  (copy)	
  NSString*	
  myObject;	
  //	
  Copy	
  the	
  object	
  during	
  assignement.	
  
@property	
  (readonly)	
  UIView*	
  rootView;	
  //	
  Create	
  only	
  a	
  getter	
  method.	
  
  	
         	
              	
          	
               	
  	
  

…	
  

And in the implementation side we have:
@synthesize	
  flag;	
  
@synthesize	
  myObject;	
  
@synthesize	
  rootView;	
  

…	
  
myObject.flag	
  =	
  YES;	
  
CGRect	
  	
  	
  viewFrame	
  =	
  myObject.rootView.frame;	
  



                                                                                                                      29
Properties

Writability

  Readwrite. You can read/write it. This is the default value.
  Readonly. You can only read it.

Setter semantics (mutually exclusive)

  Assign. Specifies that the setter uses simple assignment. This is the default value.
  Retain. Specifies that a pointer should be retained.
  Copy. Specifies that a copy of the object should be used for assignment.

Atomicity (multithreading)

  Nonatomic. Specifies that accessor methods are not atomic.
  The default value is atomic but there is no need to specify it.


                                                                                          30
Protocols and Delegates

  Protocols are not classes themselves. They simply define an interface that other objects
  are responsible for implementing


  A protocol declares methods that can be implemented by any class.


  In iOS OS, protocols are used frequently to implement delegate objects. A delegate
  object is an object that acts on behalf of, or in coordination with, another object.


  The declaration of a protocol looks similar to that of a class interface, with the exceptions
  that protocols do not have a parent class and they do not define instance variables.


  In the case of many delegate protocols, adopting a protocol is simply a matter of
  implementing the methods defined by that protocol. There are some protocols that
  require you to state explicitly that you support the protocol, and protocols can specify
  both required and optional methods.
                                                                                               31
Demo

 Fraction (without UI)
Demo: Fraction

Fraction.h	
                                               Fraction.m	
  

#import	
  <Foundation/NSObject.h>	
  	
                   #import	
  "Fraction.h"	
  	
  
                                                           #import	
  <stdio.h>	
  	
  	
  
@interface	
  Fraction:	
  NSObject	
  {	
  	
  	
  	
  
	
  	
  	
  int	
  numerator;	
  	
  	
  	
  	
  	
  
                                                           @implementation	
  Fraction	
  
	
  	
  	
  int	
  denominator;	
  	
  
	
  }	
  	
  	
  
                                                           @synthesize	
  numerator;	
  
//Properties	
  instead	
  of	
  getters	
  and	
  	
      @synthesize	
  denominator;	
  
//setters	
  
@property	
  (nonatomic)	
  int	
  numerator;	
            //	
  Output	
  Print	
  
@property	
  (nonatomic)	
  int	
  denominator;	
          -­‐(void)	
  print	
  {	
  	
  	
  	
  	
  	
  
                                                           printf("%i/%i",	
  numerator,denominator);	
  	
  
                                                           }	
  	
  	
  
//Output	
  print	
                                        @end	
  	
  
-­‐(void)	
  print;	
  	
  

                                                           …	
  
@end	
  	
  


                                                                                                                33
Demo: Fraction

main.m


#import <stdio.h>
#import "Fraction.h"

int main( int argc, const char *argv[] ) {
    Fraction *frac = [[Fraction alloc] init];
    frac.numerator = 1;
    frac.denominator=3;

    printf( "The fraction is: " );
    [frac print];
    printf( "n" );

    [frac release]
    return 0;
}




                                                             34
Strings

  The NSString class provides an object wrapper.
  Supports storing arbitrary-length strings, support for Unicode, printf-style
  formatting utilities, and more.

  Shorthand notation for creating NSString objects from constant values.
  Precede a normal, double-quoted string with the @ symbol.


  NSString*	
  	
  myString	
  =	
  @”Hello	
  Worldn";	
  


  NSString*	
  	
  anotherString	
  =	
  	
  
   	
     	
  	
  	
  	
  	
  	
  [NSString	
  stringWithFormat:@"%d	
  %s",	
  1,	
  @"String”];	
  




                                                                                                         35
Let us Code:
Outlet and Actions
                 4.
What about main method ?

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, nil);

    [pool release];

    return retVal;

}




                                                                   37
Model(delegate)



                                           View
                                                  Include
                                                  XIB files




      Protocol
   implementation
                                   Model                      Controller

                       Delegates



UIApplicationDelegate
UIAccelerometerDelegate
UILocationManagerDelegate



                                                                           38
UIApplicationDelegate

#import <UIKit/UIKit.h>

@class TutorialEvaluationViewController;



@interface TutorialEvaluationAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    TutorialEvaluationViewController *viewController;

}



@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet TutorialEvaluationViewController *viewController;

@end
                                                                                           39
UIApplicationDelegate

#import "TutorialEvaluationAppDelegate.h”
#import "TutorialEvaluationViewController.h”

@implementation TutorialEvaluationAppDelegate

@synthesize window;
@synthesize viewController;

-    (void)applicationDidFinishLaunching:(UIApplication *) application {
      // Override point for customization after app launch
      [window addSubview:viewController.view];
      [window makeKeyAndVisible];
}

-    (void) dealloc {
      [viewController release];
      [window release];
      [super dealloc];
}

@end
                                                                            40
View (go back to IB)




                                           View
                                                  Include
                                                  XIB files


                                                                   IBOutlet
                                                       IBAction
      Protocol
   implementation


                                   Model                          Controller

                       Delegates
UIApplicationDelegate
UIAccelerometerDelegate
UILocationManagerDelegate



                                                                               41
Controller



                                           View
                                                  Include
                                                  XIB files


                                                                   IBOutlet
                                                       IBAction


      Protocol
   implementation
                                   Model                          Controller

                       Delegates



UIApplicationDelegate
UIAccelerometerDelegate
UILocationManagerDelegate



                                                                               42
Outlets and Actions

  Outlet: is a pointer that points an
  object in the NIB file.




•  Action: objects in the nib can trigger
  special methods in our controller. These
  special methods are known as action
  methods.




                                                               43
FooViewController.h

#import <UIKit/UIKit.h>



@interface FooViewController : UIViewController {

    IBOutlet UILabel *label;

}

@property (retain, nonatomic) UILabel *label;

- (IBAction)buttonPressed:(id)sender;

@end



                                                                      44
FooViewController.m


#import ”FooViewController.h"

@implementation FooViewController

@synthesize label;

-(IBAction)buttonPressed:(did)sender{
     label.text = [sender titleForState:UIControlStateNormal];
}

-    (void)dealloc {
       [label release]
       [super dealloc];
}
@end



                                                                          45
Connecting

  We need to connect the elements in the interface with its functionality, i.e., we have
  to connect our View with the File's Owner.

  With this connection we are telling our controller that when our application starts it
  loads the TutorialEvaluationViewController.xib file into memory and get control of it.



                               UI




                                                                                            46
Coding


  Outlets and Actions
Solution


IBOutlet UILabel *label;
IBOutlet	
  UIImageView	
  *logo;	
  

@property	
  (nonatomic,	
  retain)	
  UILabel	
  *label;	
  
@property	
  (nonatomic,	
  retain)	
  UIImageView	
  *logo;	
  



@synthesize	
  label;	
  
@synthesize	
  logo;	
  

-­‐(IBAction)pressButtonSpanish:(id)sender{	
  
	
  	
  label.text	
  =	
  @”¡Hola!";	
  
	
  	
  logo.image	
  =	
  [UIImage	
  imageNamed:@”mexico_flag.gif"];	
  
}	
  

…	
  
Demo


 Fraction (with UI)
Let us Code:
Touch Events
            5
Handling Touch Events

All UIViewController inherit from UIResponder, and is able to handle touch Event.
In order to do this we use these three methods:



-­‐	
  (void)touchesBegan:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event;	
  

-­‐	
  (void)touchesMoved:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event;	
  

-­‐	
  (void)touchesEnded:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event;	
  




                                                                                      51
Coding


 Touch
Solution
-­‐(void)touchesBegan:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event{	
  
	
  	
  	
  touchLabel.text	
  =	
  @"began";	
  
	
  	
  	
  NSUInteger	
  numTaps	
  =	
  [[touches	
  anyObject]	
  tapCount];	
  
	
  	
  	
  if	
  (numTaps	
  ==	
  1)	
  
	
  	
  	
  	
  	
  [self.view	
  setBackgroundColor:	
  [UIColor	
  redColor]];	
  
	
  	
  	
  else	
  if	
  (numTaps	
  ==	
  2)	
  
	
  	
  	
  	
  	
  [self.view	
  setBackgroundColor:	
  [UIColor	
  blueColor]];	
  
	
  	
  	
  else	
  if	
  (numTaps	
  ==	
  3)	
  
	
  	
  	
  	
  	
  [self.view	
  setBackgroundColor:	
  [UIColor	
  yellowColor]];	
  	
  
}	
  

-­‐(void)touchesMoved:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event{	
  
	
  	
  	
  CGPoint	
  point	
  =	
  [[touches	
  anyObject]	
  locationInView:self.view];	
  
	
  	
  	
  NSString	
  *touchesMessage	
  =	
  [[NSString	
  alloc]	
  initWithFormat:@"%f,	
  %f",	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  point.x,	
  point.y];	
  
	
  	
  	
  touchLabel.text	
  =	
  touchesMessage;	
  
	
  	
  	
  [touchesMessage	
  release];	
  
}	
  

-­‐(void)touchesEnded:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event{	
  
	
  	
  	
  touchLabel.text	
  =	
  @"ended";	
  
}	
  
Demo

 Fireworks
Let us code:
Autorotate and Accelerometer
                           6
AutoRotate

The UIViewController class provides the infrastructure needed to rotate your interface and
  adjust the position of views automatically in response to orientation changes.


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation interfaceOrientation {
   return YES;
   //return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


interfaceOrientation values:

  UIInterfaceOrientationPortrait
  UIInterfaceOrientationPortraitUpsideDown
  UIInterfaceOrientationLandscapeLeft
  UIInterfaceOrientationLandscapeRight

                                                                                             56
AutoRotate adjustments




                     57
Coding


 Autorotate
Accelerometer


Measure of Gravity acceleration:

0g

1g

2.3g




                              59
Reading the Accelerometer

  UIAccelerometer object in UIKit allow you to access to the raw accelerometer
     data directly. This object reports the current accelerometer values.

  To get an instance of this class, call the sharedAccelerometer method of
     UIAccelerometer class.

    The updateInterval property define the reporting interval in seconds.


-­‐(void)viewDidLoad	
  {	
  
	
  	
  UIAccelerometer	
  *accelerometer	
  =	
  [UIAccelerometer	
  sharedAccelerometer];	
  
	
  	
  accelerometer.delegate	
  =	
  self;	
  
	
  	
  accelerometer.updateInterval	
  =	
  	
  1.0/60;	
  
	
  	
  [super	
  viewDidLoad];	
  
}	
  



                                                                                              60
Reading the Accelerometer

  A delegate (UIAccelerometerDelegate) will receive acceleration events.


@interface	
  FooViewController:	
  UIViewController	
  <UIAccelerometerDelegate>	
  



  Use   accelerometer:didAccelerate: method to process accelerometer data.


-­‐(void)accelerometer:(UIAccelerometer	
  *)accelerometer	
  didAccelerate:
                	
  (UIAcceleration	
  *)acceleration	
  {	
  	
  	
  	
  	
  
	
  	
  NSString	
  *s	
  =	
  [[NSString	
  alloc]	
  initWithFormat:@"%f,	
  %f,	
  %f",	
   	
     	
  
                	
  acceleration.x,	
  acceleration.y,	
  acceleration.z];	
  
    	
  accLabel.text	
  =	
  s;	
  
	
  	
  [s	
  release];	
  
}
                                                                                                        61
Coding


 Accelerometer
Demo


 Rolling ball
Let us Code:
Core Location
            7
Core Location


The Core Location framework monitors signals coming from cell phone towers
and Wi-Fi hotspots and uses them to triangulate the user's current position.




                                                                               65
Step One: CLLocationManager

  Create an instance of CLLocationManager class.
It	
  is	
  necessary	
  to	
  include	
  the	
  CoreLocation.framework	
  

#import	
  <CoreLocation/CoreLocation.h>	
  

@interface	
  FooViewController:	
  UIViewController<CLLocationManagerDelegate>	
  	
  



  To begin receiving notifications, assign a delegate and call the
   startUpdatingLocation method.


-­‐(void)viewDidLoad	
  {	
  
	
  	
  CLLocationManager	
  *locationManager=	
  [[CLLocationManager	
  alloc]	
  init];	
  
	
  	
  [locationManager	
  startUpdatingLocation];locationManager.delegate	
  =	
  self;	
  
	
  	
  locationManager.distanceFilter	
  =	
  kCLDistanceFilterNone;	
  	
  	
  	
  
	
  	
  locationManager.desiredAccuracy	
  =	
  kCLLocationAccuracyBest;	
  
}	
  

                                                                                                66
Step Two: CLLocation

  We need implement this:

-­‐  (void)locationManager:(CLLocationManager	
  *)manager	
  didUpdateToLocation:
  (CLLocation	
  *)newLocation	
  fromLocation:(CLLocation	
  *)oldLocation	
  {	
  

	
  	
  NSString	
  *latitudeString	
  =	
  [[NSString	
  alloc]	
  initWithFormat:@"%g°",	
  
             	
         	
       	
            	
  newLocation.coordinate.latitude];	
  

	
  	
  latitudeLabel.text	
  =	
  latitudeString;	
  
	
  	
  [latitudeString	
  release];	
  
    	
  NSString	
  *longitudeString	
  =	
  [[NSString	
  alloc]	
  initWithFormat:@"%g°",	
  	
  
    	
       	
         	
  newLocation.coordinate.longitude];	
  

	
  	
  longitudeLabel.text	
  =	
  longitudeString;	
  
	
  	
  [longitudeString	
  release];	
  
}	
  


                                                                                                      67
Demo


  LocationText
MapKit

  CLCoreLocation


  Parse KML files




                          69
Demo


  LocationMap
Graphics
       8
Quartz

  Quartz 2D is the primary two-dimensional graphics rendering
  API for iOS, part of the Core Graphics framework.

  It offers features such as: Draw or display bitmap images,
  Work with PDF documents, Beziers curves, Transformations,
  and gradients.




                                                                      72
Coding a new view

#import	
  <UIKit/UIKit.h>	
  

@interface	
  myView	
  :	
  UIView	
  {	
  

	
  	
  	
  CGPoint	
  myPoint;	
  	
  	
  
	
  	
  	
  int	
  x;	
  
	
  	
  	
  int	
  y;	
  
}	
  

@property	
  CGPoint	
  myPoint;	
  
@property	
  int	
  x;	
  
@property	
  int	
  y;	
  

-­‐(void)draw;	
  

@end	
  


                                                               73
Coding a new view
@implementation	
  myView	
  

@synthesize	
  myPoint;	
  
@synthesize	
  x;	
  
@synthesize	
  y;	
  

-­‐(id)initWithCoder:(NSCoder	
  *)coder	
  {	
  

	
  	
  	
  if	
  (self	
  =	
  [super	
  initWithCoder:coder])	
  {	
  
	
  	
  	
  	
  	
  	
  x=self.bounds.size.width	
  /	
  2;	
  
	
  	
  	
  	
  	
  	
  y=self.bounds.size.height	
  /	
  2;	
  
	
  	
  	
  }	
  
	
  	
  	
  return	
  self;	
  
}	
  

-­‐(void)touchesBegan:(NSSet	
  *)touches	
  withEvent:(UIEvent	
  *)event{	
  
	
  	
  	
  UITouch	
  *t	
  =	
  [touches	
  anyObject];	
  
	
  	
  	
  CGPoint	
  point	
  =	
  [t	
  locationInView:t.view];	
  
	
  	
  	
  x	
  =	
  point.x;	
  
	
  	
  	
  y	
  =	
  point.y;	
  
	
  	
  	
  [self	
  setNeedsDisplay];	
  
}	
  
                                                                                           74
Coding a new view

-­‐	
  (void)draw{	
  

CGContextRef	
  context	
  =	
  UIGraphicsGetCurrentContext();	
  
CGContextSetFillColorWithColor(context,	
  [UIColor	
  colorWithRed:1.0f	
  
         	
         	
          	
  green:0.0f	
  blue:0.0f	
  alpha:1.0f].CGColor);	
  	
  	
  	
  	
  
CGRect	
  patito	
  =	
  CGRectMake	
  (x,y,10,10);CGContextAddEllipseInRect
      (context,	
  patito);	
  
CGContextDrawPath(context,	
  kCGPathFillStroke);	
  
}	
  


-­‐  (void)drawRect:(CGRect)rect	
  {	
  
 	
  [self	
  draw];	
  
}	
  




                                                                                                           75
Connecting the view




                  76
Quartz Demo


  QuartzSimple
OpenGL | ES

  OpenGL is an open, cross-platform graphics standard with
  broad industry support. OpenGL greatly eases the task of
  writing real-time 2D or 3D graphics applications by providing a
  mature, well-documented graphics processing pipeline that
  supports the abstraction of current and future hardware
  accelerators.




                                                                              78
OpenGL | ES Demo


  OpenGLCube
-info-plist file
               9
plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIconFile</key>
    <string>Icon.png</string>
    <key>CFBundleIdentifier</key>
    <string>com.yourcompany.${PRODUCT_NAME:identifier}</string>




                                                                           81
plist file

    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>UIStatusBarHidden</key>
    <true/>
    <key>NSMainNibFile</key>
    <string>MainWindow</string>
</dict>
</plist>


                                                        82
References
         11
iPhone Dev Center




http://developer.apple.com/iphone




                                           84
Our Web Site




.javiergs.com




                   85
Presenters



   Javier González Sánchez
    Arizona State University
      javiergs@asu.edu
      www.javiergs.com


Maria Elena Chávez Echeagaray
    Arizona State University
    helenchavez@asu.edu
    www.helenchavez.com




                                         86

Contenu connexe

En vedette (20)

Eeuwigblijvenleren2
Eeuwigblijvenleren2Eeuwigblijvenleren2
Eeuwigblijvenleren2
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
Social media voor journalisten
Social media voor journalistenSocial media voor journalisten
Social media voor journalisten
 
201103 emotional impacts on digital media
201103 emotional impacts on digital media201103 emotional impacts on digital media
201103 emotional impacts on digital media
 
Phenomenal Oct 22, 2009
Phenomenal Oct 22, 2009Phenomenal Oct 22, 2009
Phenomenal Oct 22, 2009
 
Terofox v port catalogue (rev.01)
Terofox v port catalogue (rev.01)Terofox v port catalogue (rev.01)
Terofox v port catalogue (rev.01)
 
Oasis Training Barcelona 2014
Oasis Training Barcelona 2014Oasis Training Barcelona 2014
Oasis Training Barcelona 2014
 
Temlate Of Module
Temlate Of ModuleTemlate Of Module
Temlate Of Module
 
Tabado
TabadoTabado
Tabado
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
Deutsche Telekom BarCamp 03, 25 June 2009
Deutsche Telekom BarCamp 03, 25 June 2009Deutsche Telekom BarCamp 03, 25 June 2009
Deutsche Telekom BarCamp 03, 25 June 2009
 
Urban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsUrban Cottage + IceMilk Aprons
Urban Cottage + IceMilk Aprons
 
Vol 02 chapter 8 2012
Vol 02 chapter 8 2012Vol 02 chapter 8 2012
Vol 02 chapter 8 2012
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
201506 CSE340 Lecture 19
201506 CSE340 Lecture 19201506 CSE340 Lecture 19
201506 CSE340 Lecture 19
 
Thomasville
ThomasvilleThomasville
Thomasville
 
201506 CSE340 Lecture 16
201506 CSE340 Lecture 16201506 CSE340 Lecture 16
201506 CSE340 Lecture 16
 
201107 ICALT
201107 ICALT201107 ICALT
201107 ICALT
 
201506 CSE340 Lecture 09
201506 CSE340 Lecture 09201506 CSE340 Lecture 09
201506 CSE340 Lecture 09
 
201506 CSE340 Lecture 22
201506 CSE340 Lecture 22201506 CSE340 Lecture 22
201506 CSE340 Lecture 22
 

Similaire à 201010 SPLASH Tutorial

iphone application development
iphone application developmentiphone application development
iphone application developmentarpitnot4u
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
 
Developing Applications on iOS
Developing Applications on iOSDeveloping Applications on iOS
Developing Applications on iOSFrancisco Ramos
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentrohithn
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 
Introduction to Mobile Development
Introduction to Mobile DevelopmentIntroduction to Mobile Development
Introduction to Mobile DevelopmentPragnesh Vaghela
 
outgoing again
outgoing againoutgoing again
outgoing againspredslide
 
How Do I Pick the Best Platform for an iOS App?
How Do I Pick the Best Platform for an iOS App?How Do I Pick the Best Platform for an iOS App?
How Do I Pick the Best Platform for an iOS App?SemaphoreSoftware1
 
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanDicodingEvent
 
iPhone application development training day 1
iPhone application development training day 1iPhone application development training day 1
iPhone application development training day 1Shyamala Prayaga
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcodeSunny Shaikh
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)dwipalp
 
How to Choose the Best Platform for iOS App Development?
How to Choose the Best Platform for iOS App Development?How to Choose the Best Platform for iOS App Development?
How to Choose the Best Platform for iOS App Development?SemaphoreSoftware1
 
Overlook to the Future of Mobile Application Development- TechGropse.pdf
Overlook to the Future of Mobile Application Development- TechGropse.pdfOverlook to the Future of Mobile Application Development- TechGropse.pdf
Overlook to the Future of Mobile Application Development- TechGropse.pdfsandeepsrivastav17
 

Similaire à 201010 SPLASH Tutorial (20)

200810 - iPhone Tutorial
200810 - iPhone Tutorial200810 - iPhone Tutorial
200810 - iPhone Tutorial
 
iphone application development
iphone application developmentiphone application development
iphone application development
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Developing Applications on iOS
Developing Applications on iOSDeveloping Applications on iOS
Developing Applications on iOS
 
Hello world ios v1
Hello world ios v1Hello world ios v1
Hello world ios v1
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Ide
IdeIde
Ide
 
iOS application development
iOS application developmentiOS application development
iOS application development
 
OWASP for iOS
OWASP for iOSOWASP for iOS
OWASP for iOS
 
ios basics
ios basicsios basics
ios basics
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Introduction to Mobile Development
Introduction to Mobile DevelopmentIntroduction to Mobile Development
Introduction to Mobile Development
 
outgoing again
outgoing againoutgoing again
outgoing again
 
How Do I Pick the Best Platform for an iOS App?
How Do I Pick the Best Platform for an iOS App?How Do I Pick the Best Platform for an iOS App?
How Do I Pick the Best Platform for an iOS App?
 
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang RamadhanCara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
Cara Tepat Menjadi iOS Developer Expert - Gilang Ramadhan
 
iPhone application development training day 1
iPhone application development training day 1iPhone application development training day 1
iPhone application development training day 1
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)
 
How to Choose the Best Platform for iOS App Development?
How to Choose the Best Platform for iOS App Development?How to Choose the Best Platform for iOS App Development?
How to Choose the Best Platform for iOS App Development?
 
Overlook to the Future of Mobile Application Development- TechGropse.pdf
Overlook to the Future of Mobile Application Development- TechGropse.pdfOverlook to the Future of Mobile Application Development- TechGropse.pdf
Overlook to the Future of Mobile Application Development- TechGropse.pdf
 

Plus de Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Dernier

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

201010 SPLASH Tutorial

  • 1. Programming with iPhone SDK Xcode 3.2.4 - iOS 4.1 Javier González Sánchez Maria Elena Chávez Echeagaray Copyright is held by the author/owner(s). SPLASH 2010, October 17-21, 2010. Reno, Nevada, USA
  • 5. iOS Devices Screen size. iPhone 4 960 x 640 pixels and iPad 1024 x 768 pixels. Light mobiles. iPod (3.56 oz), iPad (1.6 lb), iPhone (4.8 oz). Yesterday one application at a time. Today multitasking. Only one window. iPhone applications only can have one window at a time. Five seconds limit. When the user hits the home button, your application will have 5 seconds to save data, close and give up its control. If it takes more than that, it will be terminated. 5
  • 6. iOS Devices CPU. Apple A4 ≈ 1 GHz. Memory administration. iPod & iPad (256 MB), iPhone (512 MB) of RAM. Without a “garbage collector”. Storage. iPod (8, 32 & 64 GB), iPad(16-64 GB), iPhone (16-32 GB). File Management. It provides each application with a sandbox (2GB), where the apps can read/write files and store data. Multitouch user interface. Other features. iPhone includes Core Location, built-in camera and photo library, a built-in accelerometer, digital compass, proximity sensor, and ambient light sensor. And a Phone with WiFi. 6
  • 7. iOS SDK 2.
  • 9. iOS Developer Program   There is a free SDK that allows you to create your applications, and test them in a Simulator on your Mac. Ok!, so what?, Is this a business?   There is a Individual/Company program or the Enterprise program. They cost $99 and $299 (annual) respectively. There is also the option of the University program for free. Once you sign into any program you can upload your applications to your device (iPod, iPad, iPhone) or distribute them through the App Store.   They take care of the process (30% revenue), you can take then care of your development.   September 2009 = 85,000 apps in the Apple Store, September 2010 = 250,000 apps.   September 2009 = 2K millions downloads in the Apple Store, September 2010 = 6.5 millions downloads. 9
  • 11. iOS SDK •  Sample code Documentation •  Reference libraries •  Coding how-to •  UIKit •  Foundation Frameworks •  OpenGL / Quartz / Core Graphics •  Media •  Xcode, Tools •  Interface Builder •  iOS Simulator 11
  • 12. Frameworks   Foundation Cocoa Touch   UIKit   OpenGL ES, Quartz, Media   OpenAL, Core Audio,   Core Animation   Core Location, Core Services   CFNetwork,   SQLite | Core Data   Security,   UNIX sockets Core OS   File system   Memory allocation 12
  • 13. Tools We will be working with:   Xcode. Apple's Integrated Development Environment (IDE).   Interface Builder (IB). Environment to facilitate the development of your GUI's and to give functionality to its components.   iPhone Simulator. It allows you to run your applications on your Mac. NOTE: iOS SDK does not allow you to upload your applications to your device (iPod / iPad / iPhone) or distribute them in the App Store.   Instruments. Environment which lets you analyze the performance of your applications while running in the simulator or on a device. 13
  • 14. Xcode 14
  • 15. Interface Builder Library View .xib file View Design area GUI elements 15
  • 16. Interface Builder   Interface Builder is the tool you use to assemble your application’s user interface visually.   After you’ve placed the components on the window’s surface, you can establish the relationships between those components and your code. When your interface looks the way you want it, you save the contents to a nib file, which is a custom resource file format.   The nib files you create in Interface Builder contain all the information that the UI Kit needs to recreate the same objects in your application at runtime. Loading a nib file creates runtime versions of all the objects stored in the file, configuring them exactly as they were in Interface Builder. 16
  • 18. Model (delegate) + View + Controller View Include XIB files Model Controller Delegates 18
  • 20. Objective-C   Is a simple computer language designed to enable sophisticated OO programming.   Extends the standard ANSI C language by providing syntax for defining classes, methods, and properties, as well as other constructs that promote dynamic extension of classes.   Based mostly on Smalltalk (class syntax and design), one of the first object-oriented programming languages.   Includes the traditional object-oriented concepts, such as encapsulation, inheritance, and polymorphism. 20
  • 21. Files 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 could 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. 21
  • 22. #import   To include header files in your source code, you can use the standard #include, but….   Objective-C provides a better way: #import. it makes sure that the same file is never included more than once.  #import  “MyAppDelegate.h”    #import  “MyViewController.h”    #import  <UIKit/UIKit.h>   22
  • 23. Class   The specification of a class in Objective-C requires two distinct pieces: the interface (.h files) and the implementation (.m files).   The interface portion contains the class declaration and defines the instance variables and methods associated with the class. @interface    …    @end     The implementation portion contains the actual code for the methods of the class.  @implementation    …    @end   23
  • 24. Class Class name @interface  MyClass  :  NSObject   Parent class {    int  count;    id  data;   Instance variables  NSString*  name;   }   -­‐  (id)initWithString:(NSString  *)aName;   methods +  (MyClass  *)createMyClassWithString:  (NSString  *)  aName;   @end   24
  • 25. Class @implementation  MyClass   Class name -­‐  (id)initWithString:(NSString  *)  aName   {          if  (self  =  [super  init])  {                  count  =  0;                  data  =  nil;   methods                name  =  [aName  copy];                  return  self;          }   }   +  (MyClass  *)createMyClassWithString:  (NSString  *)  aName   {          return  [[[self  alloc]  initWithString:aName]  autorelease];   }   @end   25
  • 26. Methods   A class in Objective-C can declare two types of methods:   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. Method type identifier One or more signature keywords  -­‐(void)insertObject:(id)anObject  atIndex:(NSUInteger)index;   Return type Parameters with (type) and name 26
  • 27. Methods So  the  declaration  of  the  method  insertObject  would  be:   -­‐(void)insertObject:(id)anObject  atIndex:(NSUInteger)index   Method type identifier, is (-) to instance methods, (+) to class methods. And  the  line  to  call  the  method  would  be:   [myArray  insertObject:anObj  atIndex:0];   27
  • 28. Properties   They are simply a shorthand for defining methods (getters and setters) that access existing instance variables.   Properties do not create new instance variables in your class declaration.   Reduce the amount of redundant code you have to writ, because most accessor methods are implemented in similar ways.   You specify the behavior you want using the property declaration and then synthesize actual getter and setter methods based on that declaration at compile time. 28
  • 29. Properties In the interface we have: {   BOOL  flag;   NSString*  myObject;   UIView*  rootView;   }   @property  BOOL  flag;   @property  (copy)  NSString*  myObject;  //  Copy  the  object  during  assignement.   @property  (readonly)  UIView*  rootView;  //  Create  only  a  getter  method.               …   And in the implementation side we have: @synthesize  flag;   @synthesize  myObject;   @synthesize  rootView;   …   myObject.flag  =  YES;   CGRect      viewFrame  =  myObject.rootView.frame;   29
  • 30. Properties Writability   Readwrite. You can read/write it. This is the default value.   Readonly. You can only read it. Setter semantics (mutually exclusive)   Assign. Specifies that the setter uses simple assignment. This is the default value.   Retain. Specifies that a pointer should be retained.   Copy. Specifies that a copy of the object should be used for assignment. Atomicity (multithreading)   Nonatomic. Specifies that accessor methods are not atomic.   The default value is atomic but there is no need to specify it. 30
  • 31. Protocols and Delegates   Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing   A protocol declares methods that can be implemented by any class.   In iOS OS, protocols are used frequently to implement delegate objects. A delegate object is an object that acts on behalf of, or in coordination with, another object.   The declaration of a protocol looks similar to that of a class interface, with the exceptions that protocols do not have a parent class and they do not define instance variables.   In the case of many delegate protocols, adopting a protocol is simply a matter of implementing the methods defined by that protocol. There are some protocols that require you to state explicitly that you support the protocol, and protocols can specify both required and optional methods. 31
  • 33. Demo: Fraction Fraction.h   Fraction.m   #import  <Foundation/NSObject.h>     #import  "Fraction.h"     #import  <stdio.h>       @interface  Fraction:  NSObject  {              int  numerator;             @implementation  Fraction        int  denominator;      }       @synthesize  numerator;   //Properties  instead  of  getters  and     @synthesize  denominator;   //setters   @property  (nonatomic)  int  numerator;   //  Output  Print   @property  (nonatomic)  int  denominator;   -­‐(void)  print  {             printf("%i/%i",  numerator,denominator);     }       //Output  print   @end     -­‐(void)  print;     …   @end     33
  • 34. Demo: Fraction main.m #import <stdio.h> #import "Fraction.h" int main( int argc, const char *argv[] ) { Fraction *frac = [[Fraction alloc] init]; frac.numerator = 1; frac.denominator=3; printf( "The fraction is: " ); [frac print]; printf( "n" ); [frac release] return 0; } 34
  • 35. Strings   The NSString class provides an object wrapper.   Supports storing arbitrary-length strings, support for Unicode, printf-style formatting utilities, and more.   Shorthand notation for creating NSString objects from constant values. Precede a normal, double-quoted string with the @ symbol. NSString*    myString  =  @”Hello  Worldn";   NSString*    anotherString  =                  [NSString  stringWithFormat:@"%d  %s",  1,  @"String”];   35
  • 36. Let us Code: Outlet and Actions 4.
  • 37. What about main method ? int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } 37
  • 38. Model(delegate) View Include XIB files Protocol implementation Model Controller Delegates UIApplicationDelegate UIAccelerometerDelegate UILocationManagerDelegate 38
  • 39. UIApplicationDelegate #import <UIKit/UIKit.h> @class TutorialEvaluationViewController; @interface TutorialEvaluationAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; TutorialEvaluationViewController *viewController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet TutorialEvaluationViewController *viewController; @end 39
  • 40. UIApplicationDelegate #import "TutorialEvaluationAppDelegate.h” #import "TutorialEvaluationViewController.h” @implementation TutorialEvaluationAppDelegate @synthesize window; @synthesize viewController; -  (void)applicationDidFinishLaunching:(UIApplication *) application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; } -  (void) dealloc { [viewController release]; [window release]; [super dealloc]; } @end 40
  • 41. View (go back to IB) View Include XIB files IBOutlet IBAction Protocol implementation Model Controller Delegates UIApplicationDelegate UIAccelerometerDelegate UILocationManagerDelegate 41
  • 42. Controller View Include XIB files IBOutlet IBAction Protocol implementation Model Controller Delegates UIApplicationDelegate UIAccelerometerDelegate UILocationManagerDelegate 42
  • 43. Outlets and Actions   Outlet: is a pointer that points an object in the NIB file. •  Action: objects in the nib can trigger special methods in our controller. These special methods are known as action methods. 43
  • 44. FooViewController.h #import <UIKit/UIKit.h> @interface FooViewController : UIViewController { IBOutlet UILabel *label; } @property (retain, nonatomic) UILabel *label; - (IBAction)buttonPressed:(id)sender; @end 44
  • 45. FooViewController.m #import ”FooViewController.h" @implementation FooViewController @synthesize label; -(IBAction)buttonPressed:(did)sender{ label.text = [sender titleForState:UIControlStateNormal]; } -  (void)dealloc { [label release] [super dealloc]; } @end 45
  • 46. Connecting   We need to connect the elements in the interface with its functionality, i.e., we have to connect our View with the File's Owner.   With this connection we are telling our controller that when our application starts it loads the TutorialEvaluationViewController.xib file into memory and get control of it. UI 46
  • 48. Solution IBOutlet UILabel *label; IBOutlet  UIImageView  *logo;   @property  (nonatomic,  retain)  UILabel  *label;   @property  (nonatomic,  retain)  UIImageView  *logo;   @synthesize  label;   @synthesize  logo;   -­‐(IBAction)pressButtonSpanish:(id)sender{      label.text  =  @”¡Hola!";      logo.image  =  [UIImage  imageNamed:@”mexico_flag.gif"];   }   …  
  • 50. Let us Code: Touch Events 5
  • 51. Handling Touch Events All UIViewController inherit from UIResponder, and is able to handle touch Event. In order to do this we use these three methods: -­‐  (void)touchesBegan:(NSSet  *)touches  withEvent:(UIEvent  *)event;   -­‐  (void)touchesMoved:(NSSet  *)touches  withEvent:(UIEvent  *)event;   -­‐  (void)touchesEnded:(NSSet  *)touches  withEvent:(UIEvent  *)event;   51
  • 53. Solution -­‐(void)touchesBegan:(NSSet  *)touches  withEvent:(UIEvent  *)event{        touchLabel.text  =  @"began";        NSUInteger  numTaps  =  [[touches  anyObject]  tapCount];        if  (numTaps  ==  1)            [self.view  setBackgroundColor:  [UIColor  redColor]];        else  if  (numTaps  ==  2)            [self.view  setBackgroundColor:  [UIColor  blueColor]];        else  if  (numTaps  ==  3)            [self.view  setBackgroundColor:  [UIColor  yellowColor]];     }   -­‐(void)touchesMoved:(NSSet  *)touches  withEvent:(UIEvent  *)event{        CGPoint  point  =  [[touches  anyObject]  locationInView:self.view];        NSString  *touchesMessage  =  [[NSString  alloc]  initWithFormat:@"%f,  %f",                                                        point.x,  point.y];        touchLabel.text  =  touchesMessage;        [touchesMessage  release];   }   -­‐(void)touchesEnded:(NSSet  *)touches  withEvent:(UIEvent  *)event{        touchLabel.text  =  @"ended";   }  
  • 55. Let us code: Autorotate and Accelerometer 6
  • 56. AutoRotate The UIViewController class provides the infrastructure needed to rotate your interface and adjust the position of views automatically in response to orientation changes. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation interfaceOrientation { return YES; //return (interfaceOrientation == UIInterfaceOrientationPortrait); } interfaceOrientation values:   UIInterfaceOrientationPortrait   UIInterfaceOrientationPortraitUpsideDown   UIInterfaceOrientationLandscapeLeft   UIInterfaceOrientationLandscapeRight 56
  • 59. Accelerometer Measure of Gravity acceleration: 0g 1g 2.3g 59
  • 60. Reading the Accelerometer   UIAccelerometer object in UIKit allow you to access to the raw accelerometer data directly. This object reports the current accelerometer values.   To get an instance of this class, call the sharedAccelerometer method of UIAccelerometer class.   The updateInterval property define the reporting interval in seconds. -­‐(void)viewDidLoad  {      UIAccelerometer  *accelerometer  =  [UIAccelerometer  sharedAccelerometer];      accelerometer.delegate  =  self;      accelerometer.updateInterval  =    1.0/60;      [super  viewDidLoad];   }   60
  • 61. Reading the Accelerometer   A delegate (UIAccelerometerDelegate) will receive acceleration events. @interface  FooViewController:  UIViewController  <UIAccelerometerDelegate>     Use accelerometer:didAccelerate: method to process accelerometer data. -­‐(void)accelerometer:(UIAccelerometer  *)accelerometer  didAccelerate:  (UIAcceleration  *)acceleration  {              NSString  *s  =  [[NSString  alloc]  initWithFormat:@"%f,  %f,  %f",        acceleration.x,  acceleration.y,  acceleration.z];    accLabel.text  =  s;      [s  release];   } 61
  • 64. Let us Code: Core Location 7
  • 65. Core Location The Core Location framework monitors signals coming from cell phone towers and Wi-Fi hotspots and uses them to triangulate the user's current position. 65
  • 66. Step One: CLLocationManager   Create an instance of CLLocationManager class. It  is  necessary  to  include  the  CoreLocation.framework   #import  <CoreLocation/CoreLocation.h>   @interface  FooViewController:  UIViewController<CLLocationManagerDelegate>       To begin receiving notifications, assign a delegate and call the startUpdatingLocation method. -­‐(void)viewDidLoad  {      CLLocationManager  *locationManager=  [[CLLocationManager  alloc]  init];      [locationManager  startUpdatingLocation];locationManager.delegate  =  self;      locationManager.distanceFilter  =  kCLDistanceFilterNone;            locationManager.desiredAccuracy  =  kCLLocationAccuracyBest;   }   66
  • 67. Step Two: CLLocation   We need implement this: -­‐  (void)locationManager:(CLLocationManager  *)manager  didUpdateToLocation: (CLLocation  *)newLocation  fromLocation:(CLLocation  *)oldLocation  {      NSString  *latitudeString  =  [[NSString  alloc]  initWithFormat:@"%g°",          newLocation.coordinate.latitude];      latitudeLabel.text  =  latitudeString;      [latitudeString  release];    NSString  *longitudeString  =  [[NSString  alloc]  initWithFormat:@"%g°",          newLocation.coordinate.longitude];      longitudeLabel.text  =  longitudeString;      [longitudeString  release];   }   67
  • 71. Graphics 8
  • 72. Quartz   Quartz 2D is the primary two-dimensional graphics rendering API for iOS, part of the Core Graphics framework.   It offers features such as: Draw or display bitmap images, Work with PDF documents, Beziers curves, Transformations, and gradients. 72
  • 73. Coding a new view #import  <UIKit/UIKit.h>   @interface  myView  :  UIView  {        CGPoint  myPoint;            int  x;        int  y;   }   @property  CGPoint  myPoint;   @property  int  x;   @property  int  y;   -­‐(void)draw;   @end   73
  • 74. Coding a new view @implementation  myView   @synthesize  myPoint;   @synthesize  x;   @synthesize  y;   -­‐(id)initWithCoder:(NSCoder  *)coder  {        if  (self  =  [super  initWithCoder:coder])  {              x=self.bounds.size.width  /  2;              y=self.bounds.size.height  /  2;        }        return  self;   }   -­‐(void)touchesBegan:(NSSet  *)touches  withEvent:(UIEvent  *)event{        UITouch  *t  =  [touches  anyObject];        CGPoint  point  =  [t  locationInView:t.view];        x  =  point.x;        y  =  point.y;        [self  setNeedsDisplay];   }   74
  • 75. Coding a new view -­‐  (void)draw{   CGContextRef  context  =  UIGraphicsGetCurrentContext();   CGContextSetFillColorWithColor(context,  [UIColor  colorWithRed:1.0f        green:0.0f  blue:0.0f  alpha:1.0f].CGColor);           CGRect  patito  =  CGRectMake  (x,y,10,10);CGContextAddEllipseInRect (context,  patito);   CGContextDrawPath(context,  kCGPathFillStroke);   }   -­‐  (void)drawRect:(CGRect)rect  {    [self  draw];   }   75
  • 78. OpenGL | ES   OpenGL is an open, cross-platform graphics standard with broad industry support. OpenGL greatly eases the task of writing real-time 2D or 3D graphics applications by providing a mature, well-documented graphics processing pipeline that supports the abstraction of current and future hardware accelerators. 78
  • 79. OpenGL | ES Demo   OpenGLCube
  • 81. plist file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleDisplayName</key> <string>${PRODUCT_NAME}</string> <key>CFBundleExecutable</key> <string>${EXECUTABLE_NAME}</string> <key>CFBundleIconFile</key> <string>Icon.png</string> <key>CFBundleIdentifier</key> <string>com.yourcompany.${PRODUCT_NAME:identifier}</string> 81
  • 82. plist file <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>${PRODUCT_NAME}</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1.0</string> <key>UIStatusBarHidden</key> <true/> <key>NSMainNibFile</key> <string>MainWindow</string> </dict> </plist> 82
  • 86. Presenters Javier González Sánchez Arizona State University javiergs@asu.edu www.javiergs.com Maria Elena Chávez Echeagaray Arizona State University helenchavez@asu.edu www.helenchavez.com 86