Académique Documents
Professionnel Documents
Culture Documents
• UIKit
• Ejemplo de Aplicación
iPhone
iPod touch
iPad
• Tienda de aplicaciones
• ¡+300.000 aplicaciones!
• Gratuitas y de pago
• 70/30 R/S
• 79 € / año
• Ejecutar aplicaciones en el dispositivo (no
sólo simulador)
• Distribución en el App Store
http://developer.apple.com/programs/ios/
© 2010 Manuel Freire / Cátedra UAM-Telefónica
iOS
Cocoa Touch
Media
Core Services
Core OS
• Threads
Media
• Sockets
• File System
Core OS
• Bonjour
• CFNetwork
Media
• Core Data
• Core Location
Core OS
• Store Kit
• Core Animation
Media
• OpenGL ES
• Media Player
Core OS
• OpenAL
• Map Kit
Media
• Game Kit
• Otros: Push
Notifications,
Core OS
Multitasking, etc.
Media Media
Core OS Core OS
iOS Mac OS X
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Diseño
Dispositivo Resolución
iPhone (< 4) 320x480
iPhone 4 640x960
iPad 768x1024
1. Apps nativas
2. Web apps
3. Apps híbridas
Objective-C
Java
C/C++
Flash
HTML5
• Basado en ANSI C
• Orientado a objetos
• Sintaxis relativamente simple
• Combinable con C++ (Objective-C++)
Gato
Edad
Peso Atributos
Color
Comer
Dormir
Métodos
Clase
Clase Objetos
- (id)initWithPosition:(CGPoint)pos R:(float)r;
Métodos
- (float)getArea;
@end
Circle.h
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Clases
@implementation Circle
- (id)initWithPosition:(CGPoint)pos R:(float)r
{
! self = [super init];
! if (self) {
! ! m_pos = pos;
! ! m_r = r;
! }
! return self;
}
- (float)getArea
{
! return 2.0 * 3.141592 * m_r;
}
@end
Circle.m
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Creación de Objetos
• Dos pasos:
[c getArea];
[ball calculatePositionForTime:10.0];
[self doSomething];
@end
@implementation MyClass
• IDE
• Mac OS X y iOS
• Debugger
• iPhone Simulator
• Herramienta de diseño
de interfaces de usuario
• Conexión entre
elementos de la interfaz
y las clases definidas en
el código
• Define la ventana de la
aplicación
• Contiene la vista
(UIView) principal de la
aplicación
@end
#import <UIKit/UIKit.h>
#import "MyViewController.h"
@end
HolaMundoAppDelegate.h
© 2010 Manuel Freire / Cátedra UAM-Telefónica
UIViewController: Inicialización
// ...
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)
launchOptions
{
! myViewController = [[MyViewController alloc]
! ! initWithNibName:@"MyViewController" bundle:nil];
! [window addSubview:myViewController.view];
[window makeKeyAndVisible];
return YES;
}
// ...
HolaMundoAppDelegate.m
© 2010 Manuel Freire / Cátedra UAM-Telefónica
UIViewController: Destrucción
// ...
- (void)dealloc
{
! [myViewController release];
[window release];
[super dealloc];
}
// ...
HolaMundoAppDelegate.m
© 2010 Manuel Freire / Cátedra UAM-Telefónica
UIViewController: Nib
#import <UIKit/UIKit.h>
@end
MyViewController.h
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Outlets
#import <UIKit/UIKit.h>
- (IBAction)countLetters;
@end
MyViewController.h
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Acciones
// ...
- (IBAction)countLetters
{
! int numLetters = [input.text length];
! result.text = [NSString stringWithFormat:@"%d
letras", numLetters];
! result.hidden = NO;
}
// ...
MyViewController.mm
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Acciones
#import <UIKit/UIKit.h>
- (IBAction)countLetters;
@end
MyViewController.h
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Text Field Delegate
// ...
- (BOOL)textFieldShouldReturn:(UITextField*)theTextField
{
! if (theTextField == input)
! {
! ! [input resignFirstResponder];
! }
! return YES;
}
// ...
MyViewController.m
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Build & Go
• Reference counting
• Garbage collection (no disponible en iOS)
MyClass MyClass
#1 #2
MyClass MyClass
#1 #2
• API de gráficos 3D de
bajo nivel
• Permite especificar la
geometría y propiedades
de objetos (color,
iluminación, texturas)
• Subconjunto de OpenGL
iPhone
1.1 iPhone 3G Función fija
iPod touch (1-3 gen)
iPhone 3GS
iPhone 4
2.0 Programable (shaders)
iPod touch (4 gen)
iPad
-(void)setupAccelerometer
{
UIAccelerometer* accel = [UIAccelerometer sharedAccelerometer];
accel.updateInterval = 1 / kAccelerometerFrequency;
accel.delegate = self; // Debe adoptar UIAccelerometerDelegate
}
• Amigos
• Multiplayer online
• Leaderboards
• Achievements
• Background audio
• VoIP
• Background location
• Push notifications
• Local notifications
• Task finishing
• Fast app switching
! if (connection)
! {
! ! // Inicializar la variable que gestionará los datos recibidos
! ! receivedData = [[NSMutableData data] retain];
! }
! else
! {
! ! // Informar al usuario que la conexión ha fallado
! }
}
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
! // Este método se llama cuando falla la conexión
!
[connection release];
[receivedData release];
!
NSLog(@"La conexión ha fallado. Error: %@ %@",
[error localizedDescription],
[[error userInfo]
objectForKey:NSErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
! // Este método se llama cuando la conexión ha finalizado con
! // éxito
• Incluye:
• Guías
• Artículos
• Código de ejemplo
• Vídeos explicativos
https://developer.apple.com/library/ios/
© 2010 Manuel Freire / Cátedra UAM-Telefónica
Guías para principiantes
• iOS Overview
• etc.