Mais conteúdo relacionado Semelhante a Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014 (20) Conceitos e prática no desenvolvimento iOS - Mobile Conf 201418. Ciclo de Vida - App
Aplicação
não está
rodando
Usuário
clica no ícone
da app
application:didFinishLauchingWithOptions:
applicationDidBecomeActive:
Aplicação
rodando
Usuário clica
em Home, ou recebe
chamada telefônica/
SMS
applicationWillResignActive:
applicationDidEnterBackground:
Aplicação em
backgroung
Usuário
clica no ícone
da app
applicationWillEnterForeground:
19. Ciclo de Vida - App
Aplicação
não está
rodando
Usuário
clica no ícone
da app
application:didFinishLauchingWithOptions:
applicationDidBecomeActive:
Aplicação
rodando
Usuário clica
em Home, ou recebe
chamada telefônica/
SMS
applicationWillResignActive:
applicationDidEnterBackground:
Aplicação em
backgroung
Usuário
clica no ícone
da app
applicationWillEnterForeground:
28. NSIndexPath
"The UIKit framework adds programming interfaces to the NSIndexPath class of the
Foundation framework to facilitate the identification of rows and sections in
UITableView objects and the identification of items and sections in UICollectionView
objects."
https://developer.apple.com/library/ios/documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/
Reference.html
36. Exemplo
-(IBAction)carregaLista:(UIButton *) botao !
{
! [self performSelectorInBackground: @selector(buscaMotos) withObject: nil];!
}
-(void)buscaMotos!
{
//faz a comunicação com algum webservice
[self performSelectorOnMainThread @selector(atualizaTabela:) withObject:
arrayDeDados waitUntilDone: NO];!
}
37. Exemplo
-(IBAction)carregaLista:(UIButton *) botao !
{
! [self performSelectorInBackground: @selector(buscaMotos) withObject: nil];!
}
-(void)buscaMotos!
{
//faz a comunicação com algum webservice
[self performSelectorOnMainThread @selector(atualizaTabela:) withObject: nil waitUntilDone:
NO];!
}!
-(void)atualizaTabela:(NSObject*) object!
{
! ! [self.tableView reloadData];!
}
39. Exemplo
-(IBAction)carregaLista:(UIButton *) botao {
NSOperationQueue * queue = [[NSOperationQueue alloc]init];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget: self
selector: @selector(downloadMotos) object:nil];
!
[queue addOperation:operation];
}
!
-(void)downloadPosts{
//faz a comunicação com algum webservice!
[self performSelectorOnMainThread @selector(atualizaTabela:) withObject: arrayDeDados
waitUntilDone: NO];
!
}
!
-(void)atualizaTabela:(NSObject*) object{
//...
[self.tableView reloadData];
}
41. Exemplo
NSArray *images = @[@"http://example.com/image1.png",
@"http://example.com/image2.png",
@"http://example.com/image3.png",
@"http://example.com/image4.png"];
!
dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL);
!
for (NSString *urlString in images) {
dispatch_async(imageQueue, ^{
NSURL *url = [NSURL URLWithString:urlString];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
!
NSUInteger imageIndex = [images indexOfObject:urlString];
UIImageView *imageVIew = (UIImageView *)[self.view viewWithTag:imageIndex];
if (!imageView) return;
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
[imageVIew setImage:image];
});
});
}
44. Exemplo(GET)
NSString * url = @“http://projetows.heroku.com/motos.json”
!
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL
URLWithString: url] ];
!
[NSURLConnection sendAsynchronousRequest:request queue:
[NSOperationQueue mainQueue]
completionHandler: ^(NSURLResponse *response, NSData *data, NSError
*connectionError)
{
// manipula resposta
}
];
46. Exemplo (GET)
NSString * url = @“http://projetows.heroku.com/motos.json”
!
NSURLSession *session = [NSURLSession sharedSession];
[session dataTaskWithURL: [NSURL URLWithString:
url]completionHandler:^(NSData *data, NSURLResponse *response,
NSError *error)
{
//manipula resposta!
}
] resume];
50. Exemplo
NSString *url = @“http://projetows.heroku.com/motos.json";!
!
NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]];!
!
NSError *error;!
NSArray *resultados = [NSJSONSerialization JSONObjectWithData: jsonData
options:NSJSONReadingMutableContainers error:&error];!
if(!error) {!
! for(NSDictionary * moto in resultados){!
! ! NSString *marca = [moto objectForKey:@"marca"];!
! ! NSString *modelo = [moto objectForKey:@"modelo"];!
! ! NSLog(@"Marca: %@, modelo: %@", marca, modelo);!
! }!
}!
54. Exemplo
!
NSString * url = @“projetows.heroku.com/motos.json”!
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];!
!
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {!
! !
! self.json = responseObject;!
! for(NSDictionary * moto in self.json){!
!
! NSString *marca = [moto objectForKey:@"marca"];!
! ! NSString *modelo = [moto objectForKey:@"modelo"];!
! ! NSLog(@"Marca: %@, modelo: %@", marca, modelo);!
! }!
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {!
NSLog(@"Error: %@", error);!
!
}];!
}!
67. KIF Acceptance Tests
@implementation LoginTests
!
- (void)beforeEach
{
[tester navigateToLoginPage];
}
!
- (void)afterEach
{
[tester returnToLoggedOutHomeScreen];
}
!
- (void)testSuccessfulLogin
{
[tester enterText:@"user@example.com" intoViewWithAccessibilityLabel:@"Login User Name"];
[tester enterText:@"thisismypassword" intoViewWithAccessibilityLabel:@"Login Password"];
[tester tapViewWithAccessibilityLabel:@"Log In"];
!
// Verify that the login succeeded
[tester waitForTappableViewWithAccessibilityLabel:@"Welcome"];
}
!
@end