SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
iOS Development
                 Lecture 2 - The practical stuff



Petr Dvořák
Partner & iOS Development Lead
@joshis_tweets
Outline
Outline
• Using location services and maps
  • Adding maps to an app
  • Determining user’s location
  • Geocoding/Reverse geocoding
Outline
• Using system dialogs
  • Picking a contact
  • Taking a photo
  • Composing an e-mail or SMS
Outline
• Getting a bit social
  • Twitter API
  • Facebook iOS SDK
Outline
• Threading
  • NSThread
  • GCD (Grand Central Dispatch)
  • NSOperation
Outline
• If there is still time...
  • Using UIWebView
  • iOS app localization
Maps & Location
MapKit

• Implementation of
 Google Maps

• High-level API
• Annotations, Routes,
 Overlays
MKMapView
• UIView subclass
• Based on adding “annotations”
  • = model classes
• Support for user’s location
• Customizable maps & annotations
• Delegate-based API
MKAnnotation
• Protocol that enables model class for
  showing up on maps
 • coordinate, title, subtitle
• MKPlacemark
  • conforms to MKAnnotation
  • country, state, city, address
MKAnnotationView
• View related to a particular
  MKAnnotation instance
• Reused in the map view
• MKPinAnnotationView
  • The classic “iOS map pin”
  • Three colors
Core Location
• Access to GPS module
• Configurable precision (vs. time)
• Significant Location Changes
• May run on background
CLLocationManager
• Provides callbacks for location and
  heading
• Delegate based
• Check for availability and state of the
  location services before using
CLGeocoder
• Allows geocoding and reverse
  geocoding
• Does not use Google API
 •   ... doesn’t work perfectly outside the USA

• Block based
CLGeocoder* g = [[CLGeocoder alloc] init];

[g reverseGeocodeLocation:location
        completionHandler:^(NSArray *placemark, NSError *error) {
    // ...
}];

[g geocodeAddressString:@”Brno”
      completionHandler: ^(NSArray *placemark, NSError *error) {
    // ...
}];

// [g cancelGeocode];
System dialogs
System dialogs
• Allow performing usual tasks in
  a consistent manner
• Complete process handling
• Delegate based
Address Book
• Creating and searching contacts
• Allows manual access via C API
 •   ABAddressBookCreate

 •   ABAddressBookCopyArrayOfAllPeople

 •   ABAddressBookSave

• Contains predefined dialogs
ABPeoplePickerNavigationController

 • System dialog for picking a contact
 • Allows picking a contact or a contact
   property
ABPeoplePickerNavigationController *pp =
    [[ABPeoplePickerNavigationController alloc] init];
pp.peoplePickerDelegate = self;
[self presentModalViewController:pp
                        animated:YES];

//...

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)p
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier
{
    //...
}
ABNewPersonViewController
• System dialog for creating a contact
• May be pre-initialized
ABPersonViewController
• System dialog for displaying a contact
• Optional editing
UIImagePickerController
• System dialog for picking a photo
• Uses “sourceType” flag to determine
  source
 • camera, library, saved photos
• Check for camera before touching it
• Delegate based
MFMailComposeViewController

• System dialog for composing an
  e-mail message
• May be pre-filled with e-mail data
• Support for attachments
• + (BOOL) canSendMail;
MFMessageComposeViewController

 • System dialog for composing an
   SMS message
 • No MMS / attachments
 • May be pre-filled with message body
   and recipients (string array)
 • + (BOOL) canSendText;
Social Networks
Twitter API
• Native Twitter support
  since iOS 5
• Uses Twitter app for
  authentication
• Twitter uses OAuth 1.0a
  under the hood =>
  secure, hard to
  implement
TWTweetComposeViewController

 • System dialog for composing an
   Tweet
 • Text, Images, URLs
  •   add methods return NO if length exceeds 140 chars

 • Block based
  •   TWTweetComposeViewControllerCompletionHandler

 • + (BOOL) canSendTweet;
Facebook iOS SDK

• Facebook publishes official iOS SDK
 •   https://github.com/facebook/facebook-ios-sdk

• Requires Facebook application (web)
• Uses official Facebook app for
  authentication
 •   Alternatively: web authentication, embedded FB authentication dialog


• Uses URL scheme handling
Threading
Why threads?

• Slow operations must not block UI
  • Network operations
  • Computations
  • Filesystem operations
NSThread

• Low level thread abstraction
• Requires you to do all the
  synchronisation manually
- (void) detachAsyncOperation {
    [NSThread detachNewThreadSelector:@selector(operation:)
                     toTarget:self
                     withObject:contextData];
}


- (void) operation:(id)contextData {
    @autorelease {
        // slow code here
        // ...
        [self performSelectorOnMainThread:@selector(updateUI:)
                               withObject:contextData
                            waitUntilDone:NO];
    }
}
GCD

• Working with NSThread is difficult
• GCD makes an abstraction above
  threads
• C API, functions/macros starting with
  “dispatch_” prefix
Dispatch Queue

• Queue of blocks to be performed
 •   FIFO, synchronized

• Reference-counted
 •   dispatch_queue_create ➞ dispatch_release

• One queue per use-case
dispatch_queue_t main_queue = dispatch_get_main_queue()
dispatch_queue_t network_queue = dispatch_get_global_queue(priority, 0);
// dispatch_queue_t network_queue2 =
//             dispatch_queue_create("eu.inmite.net", NULL);

dispatch_async(network_queue, ^ {
    // some slow code
    dispatch_async(main_queue, ^{
        // update UI
    });
    // dispatch_release(network_queue2);
});
Dispatch Semaphore

•   dispatch_semaphore_create
•   dispatch_semaphore_wait
•   dispatch_semaphore_signal
NSOperation
• Abstraction above “operation”
• Meant to be subclassed
 •   main - code to be executed

 •   start - start the operation

 •   cancel - set the cancel flag


• Operation priority
• Dependencies
 •   [op1 addDependency:op2];
NSInvocationOperation
• NSOperation subclass
• Operation based on target & selector

 [[NSInvocationOperation alloc] initWithTarget:target
                                      selector:selector
                                        object:context];
NSBlockOperation
• NSOperation subclass
• Operation based on block

 [NSBlockOperation blockOperationWithBlock:^{
       // some code...
 }];
NSOperationQueue
• NSOperations are not meant to be
  run directly
• NSOperationQueue runs the
  operations correctly
• Configurable number of concurrent
  operations
NSOperationQueue


 NSOperationQueue *queue = [NSOperationQueue mainQueue];
 // queue = [NSOperationQueue currentQueue];
 // queue = [[NSOperationQueue alloc] init];

 [queue addOperation:anOperation];
Singleton pattern

• Assures access to a shared instance
• Usually allows multiple instance
  creation
• Simple pattern, many problems
• Threading
// within class Foo
+ (Foo*) getDefault {
    static Foo *inst = nil;
    if (!inst) {
        inst = [[Foo alloc] init];
    }
    return inst;
}
// within class Foo
+ (Foo*) getDefault {
    static Foo *inst = nil;
    @synchronized (self) {
        if (!inst) {
            inst = [[Foo alloc] init];
        }
    }
    return inst;
}
// within class Foo
+ (Foo*) getDefault {
    static Foo *inst = nil;
    if (!inst) { // double-check locking
        @synchronized (self) {
            if (!inst) {
                 inst = [[Foo alloc] init];
            }
        }
    }
    return inst;
}
// within class Foo
+ (Foo*) getDefault {
    static volatile Foo *inst = nil;
    if (!inst) { // double-check locking
        @synchronized (self) {
            if (!inst) {
                 Foo *tmp = [[Foo alloc] init];
                 OSMemoryBarrier();
                 inst = tmp;
            }
        }
    }
    OSMemoryBarrier();
    return inst;
}
// within class Foo
+ (Foo*) getDefault {
    static volatile Foo *inst;
    static dispatch_once_t pred;
    dispatch_once(&pred, ^ {
        inst = [[Foo alloc] init];
    });
    return inst;
}
Thank you
                   http://www.inmite.eu/talks



Petr Dvořák
Partner & iOS Development Lead
@joshis_tweets

Weitere ähnliche Inhalte

Was ist angesagt?

Real time server
Real time serverReal time server
Real time serverthepian
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0GrUSP
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourCarl Brown
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST serviceWO Community
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?Sam Thomas
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSTechWell
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Data Con LA
 
ERRest - The Next Steps
ERRest - The Next StepsERRest - The Next Steps
ERRest - The Next StepsWO Community
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用Felinx Lee
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference CountingGiuseppe Arici
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]Guillermo Paz
 
Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Mikhail Sosonkin
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CAlexis Gallagher
 

Was ist angesagt? (20)

JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
Real time server
Real time serverReal time server
Real time server
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
ERRest in Depth
ERRest in DepthERRest in Depth
ERRest in Depth
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST service
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...
 
ERRest - The Next Steps
ERRest - The Next StepsERRest - The Next Steps
ERRest - The Next Steps
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
ORMs in Golang
ORMs in GolangORMs in Golang
ORMs in Golang
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
 
New Design of OneRing
New Design of OneRingNew Design of OneRing
New Design of OneRing
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]
 
Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016Owasp orlando, april 13, 2016
Owasp orlando, april 13, 2016
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 

Andere mochten auch

Vývoj aplikací pro iOS
Vývoj aplikací pro iOSVývoj aplikací pro iOS
Vývoj aplikací pro iOSPetr Dvorak
 
mDevCamp 2014 - Bezpečnost v kontextu internetu věcí
mDevCamp 2014 - Bezpečnost v kontextu internetu věcímDevCamp 2014 - Bezpečnost v kontextu internetu věcí
mDevCamp 2014 - Bezpečnost v kontextu internetu věcíPetr Dvorak
 
New Media Inspiration 2015 - Invisible technologies and context inside and ar...
New Media Inspiration 2015 - Invisible technologies and context inside and ar...New Media Inspiration 2015 - Invisible technologies and context inside and ar...
New Media Inspiration 2015 - Invisible technologies and context inside and ar...Petr Dvorak
 
SmartDevCon - Katowice - 2013
SmartDevCon - Katowice - 2013SmartDevCon - Katowice - 2013
SmartDevCon - Katowice - 2013Petr Dvorak
 
Bankovní aplikace a jejich bezpečnost
Bankovní aplikace a jejich bezpečnostBankovní aplikace a jejich bezpečnost
Bankovní aplikace a jejich bezpečnostPetr Dvorak
 
Lime - Push notifications. The big way.
Lime - Push notifications. The big way.Lime - Push notifications. The big way.
Lime - Push notifications. The big way.Petr Dvorak
 

Andere mochten auch (6)

Vývoj aplikací pro iOS
Vývoj aplikací pro iOSVývoj aplikací pro iOS
Vývoj aplikací pro iOS
 
mDevCamp 2014 - Bezpečnost v kontextu internetu věcí
mDevCamp 2014 - Bezpečnost v kontextu internetu věcímDevCamp 2014 - Bezpečnost v kontextu internetu věcí
mDevCamp 2014 - Bezpečnost v kontextu internetu věcí
 
New Media Inspiration 2015 - Invisible technologies and context inside and ar...
New Media Inspiration 2015 - Invisible technologies and context inside and ar...New Media Inspiration 2015 - Invisible technologies and context inside and ar...
New Media Inspiration 2015 - Invisible technologies and context inside and ar...
 
SmartDevCon - Katowice - 2013
SmartDevCon - Katowice - 2013SmartDevCon - Katowice - 2013
SmartDevCon - Katowice - 2013
 
Bankovní aplikace a jejich bezpečnost
Bankovní aplikace a jejich bezpečnostBankovní aplikace a jejich bezpečnost
Bankovní aplikace a jejich bezpečnost
 
Lime - Push notifications. The big way.
Lime - Push notifications. The big way.Lime - Push notifications. The big way.
Lime - Push notifications. The big way.
 

Ähnlich wie iOS 2 - The practical Stuff

FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Satoshi Asano
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCDrsebbe
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone developmentVonbo
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIsJulian Viereck
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Sarp Erdag
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEHendrik Ebel
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRichard Lee
 
Using Protocol to Refactor
Using Protocol to Refactor Using Protocol to Refactor
Using Protocol to Refactor Green Chiu
 
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache StormReal-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache StormDavorin Vukelic
 
SwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupSwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupErnest Jumbe
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 

Ähnlich wie iOS 2 - The practical Stuff (20)

FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
 
Pioc
PiocPioc
Pioc
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone development
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEE
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Using Protocol to Refactor
Using Protocol to Refactor Using Protocol to Refactor
Using Protocol to Refactor
 
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache StormReal-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache Storm
 
SwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup GroupSwampDragon presentation: The Copenhagen Django Meetup Group
SwampDragon presentation: The Copenhagen Django Meetup Group
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 

Mehr von Petr Dvorak

Czech Banks are Under Attack, Clients Lose Money.
Czech Banks are Under Attack, Clients Lose Money.Czech Banks are Under Attack, Clients Lose Money.
Czech Banks are Under Attack, Clients Lose Money.Petr Dvorak
 
Innovations on Banking - Digital Banking Security in the Age of Open Banking
Innovations on Banking - Digital Banking Security in the Age of Open BankingInnovations on Banking - Digital Banking Security in the Age of Open Banking
Innovations on Banking - Digital Banking Security in the Age of Open BankingPetr Dvorak
 
mDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appmDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appPetr Dvorak
 
Jak vypadá ideální bankovní API?
Jak vypadá ideální bankovní API? Jak vypadá ideální bankovní API?
Jak vypadá ideální bankovní API? Petr Dvorak
 
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikací
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikacíSmart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikací
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikacíPetr Dvorak
 
Bankovní API ve světě
Bankovní API ve světěBankovní API ve světě
Bankovní API ve světěPetr Dvorak
 
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšíte
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšítePSD2 a bankovní API: Top 5 mýtů, které dnes slyšíte
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšítePetr Dvorak
 
Představení Zingly API Serveru a popis integrace
Představení Zingly API Serveru a popis integracePředstavení Zingly API Serveru a popis integrace
Představení Zingly API Serveru a popis integracePetr Dvorak
 
Lime - PowerAuth 2.0 and mobile QRToken introduction
Lime - PowerAuth 2.0 and mobile QRToken introductionLime - PowerAuth 2.0 and mobile QRToken introduction
Lime - PowerAuth 2.0 and mobile QRToken introductionPetr Dvorak
 
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...Petr Dvorak
 
Co musí banka udělat pro zapojení do Zingly?
Co musí banka udělat pro zapojení do Zingly?Co musí banka udělat pro zapojení do Zingly?
Co musí banka udělat pro zapojení do Zingly?Petr Dvorak
 
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0Bezpečnost Zingly a detaily protokolu PowerAuth 2.0
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0Petr Dvorak
 
Zingly - Single app for all banks
Zingly - Single app for all banksZingly - Single app for all banks
Zingly - Single app for all banksPetr Dvorak
 
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?Petr Dvorak
 
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?Webinář: Co je to iBeacon a proč by vás to mělo zajímat?
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?Petr Dvorak
 
Chytré telefony v ČR - H1/2015
Chytré telefony v ČR -  H1/2015Chytré telefony v ČR -  H1/2015
Chytré telefony v ČR - H1/2015Petr Dvorak
 
What are "virtual beacons"?
What are "virtual beacons"?What are "virtual beacons"?
What are "virtual beacons"?Petr Dvorak
 
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatele
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatelemDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatele
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatelePetr Dvorak
 
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatele
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživateleiCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatele
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatelePetr Dvorak
 
Lime - Brand Guidelines
Lime - Brand GuidelinesLime - Brand Guidelines
Lime - Brand GuidelinesPetr Dvorak
 

Mehr von Petr Dvorak (20)

Czech Banks are Under Attack, Clients Lose Money.
Czech Banks are Under Attack, Clients Lose Money.Czech Banks are Under Attack, Clients Lose Money.
Czech Banks are Under Attack, Clients Lose Money.
 
Innovations on Banking - Digital Banking Security in the Age of Open Banking
Innovations on Banking - Digital Banking Security in the Age of Open BankingInnovations on Banking - Digital Banking Security in the Age of Open Banking
Innovations on Banking - Digital Banking Security in the Age of Open Banking
 
mDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking appmDevCamp 2016 - Zingly, or how to design multi-banking app
mDevCamp 2016 - Zingly, or how to design multi-banking app
 
Jak vypadá ideální bankovní API?
Jak vypadá ideální bankovní API? Jak vypadá ideální bankovní API?
Jak vypadá ideální bankovní API?
 
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikací
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikacíSmart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikací
Smart Cards and Devices Forum 2016 - Bezpečnost multi-banking mobilních aplikací
 
Bankovní API ve světě
Bankovní API ve světěBankovní API ve světě
Bankovní API ve světě
 
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšíte
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšítePSD2 a bankovní API: Top 5 mýtů, které dnes slyšíte
PSD2 a bankovní API: Top 5 mýtů, které dnes slyšíte
 
Představení Zingly API Serveru a popis integrace
Představení Zingly API Serveru a popis integracePředstavení Zingly API Serveru a popis integrace
Představení Zingly API Serveru a popis integrace
 
Lime - PowerAuth 2.0 and mobile QRToken introduction
Lime - PowerAuth 2.0 and mobile QRToken introductionLime - PowerAuth 2.0 and mobile QRToken introduction
Lime - PowerAuth 2.0 and mobile QRToken introduction
 
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...
Zingly - Dopad multi-bankingu a otevřených bankovních API do obchodního fungo...
 
Co musí banka udělat pro zapojení do Zingly?
Co musí banka udělat pro zapojení do Zingly?Co musí banka udělat pro zapojení do Zingly?
Co musí banka udělat pro zapojení do Zingly?
 
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0Bezpečnost Zingly a detaily protokolu PowerAuth 2.0
Bezpečnost Zingly a detaily protokolu PowerAuth 2.0
 
Zingly - Single app for all banks
Zingly - Single app for all banksZingly - Single app for all banks
Zingly - Single app for all banks
 
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?
Fashiontech 2015 - iBeacon: Co to je a k čemu je to dobré?
 
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?Webinář: Co je to iBeacon a proč by vás to mělo zajímat?
Webinář: Co je to iBeacon a proč by vás to mělo zajímat?
 
Chytré telefony v ČR - H1/2015
Chytré telefony v ČR -  H1/2015Chytré telefony v ČR -  H1/2015
Chytré telefony v ČR - H1/2015
 
What are "virtual beacons"?
What are "virtual beacons"?What are "virtual beacons"?
What are "virtual beacons"?
 
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatele
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatelemDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatele
mDevCamp 2015 - iBeacon aneb jak ochytřit vaše aplikace o kontext uživatele
 
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatele
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživateleiCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatele
iCON DEV - iBeacon, aneb jak ochytřit vaše aplikace o kontext uživatele
 
Lime - Brand Guidelines
Lime - Brand GuidelinesLime - Brand Guidelines
Lime - Brand Guidelines
 

Kürzlich hochgeladen

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

iOS 2 - The practical Stuff

  • 1. iOS Development Lecture 2 - The practical stuff Petr Dvořák Partner & iOS Development Lead @joshis_tweets
  • 3. Outline • Using location services and maps • Adding maps to an app • Determining user’s location • Geocoding/Reverse geocoding
  • 4. Outline • Using system dialogs • Picking a contact • Taking a photo • Composing an e-mail or SMS
  • 5. Outline • Getting a bit social • Twitter API • Facebook iOS SDK
  • 6. Outline • Threading • NSThread • GCD (Grand Central Dispatch) • NSOperation
  • 7. Outline • If there is still time... • Using UIWebView • iOS app localization
  • 9. MapKit • Implementation of Google Maps • High-level API • Annotations, Routes, Overlays
  • 10. MKMapView • UIView subclass • Based on adding “annotations” • = model classes • Support for user’s location • Customizable maps & annotations • Delegate-based API
  • 11. MKAnnotation • Protocol that enables model class for showing up on maps • coordinate, title, subtitle • MKPlacemark • conforms to MKAnnotation • country, state, city, address
  • 12. MKAnnotationView • View related to a particular MKAnnotation instance • Reused in the map view • MKPinAnnotationView • The classic “iOS map pin” • Three colors
  • 13. Core Location • Access to GPS module • Configurable precision (vs. time) • Significant Location Changes • May run on background
  • 14. CLLocationManager • Provides callbacks for location and heading • Delegate based • Check for availability and state of the location services before using
  • 15. CLGeocoder • Allows geocoding and reverse geocoding • Does not use Google API • ... doesn’t work perfectly outside the USA • Block based
  • 16. CLGeocoder* g = [[CLGeocoder alloc] init]; [g reverseGeocodeLocation:location completionHandler:^(NSArray *placemark, NSError *error) { // ... }]; [g geocodeAddressString:@”Brno” completionHandler: ^(NSArray *placemark, NSError *error) { // ... }]; // [g cancelGeocode];
  • 18. System dialogs • Allow performing usual tasks in a consistent manner • Complete process handling • Delegate based
  • 19. Address Book • Creating and searching contacts • Allows manual access via C API • ABAddressBookCreate • ABAddressBookCopyArrayOfAllPeople • ABAddressBookSave • Contains predefined dialogs
  • 20. ABPeoplePickerNavigationController • System dialog for picking a contact • Allows picking a contact or a contact property
  • 21. ABPeoplePickerNavigationController *pp = [[ABPeoplePickerNavigationController alloc] init]; pp.peoplePickerDelegate = self; [self presentModalViewController:pp animated:YES]; //... - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)p shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { //... }
  • 22. ABNewPersonViewController • System dialog for creating a contact • May be pre-initialized ABPersonViewController • System dialog for displaying a contact • Optional editing
  • 23. UIImagePickerController • System dialog for picking a photo • Uses “sourceType” flag to determine source • camera, library, saved photos • Check for camera before touching it • Delegate based
  • 24. MFMailComposeViewController • System dialog for composing an e-mail message • May be pre-filled with e-mail data • Support for attachments • + (BOOL) canSendMail;
  • 25. MFMessageComposeViewController • System dialog for composing an SMS message • No MMS / attachments • May be pre-filled with message body and recipients (string array) • + (BOOL) canSendText;
  • 27. Twitter API • Native Twitter support since iOS 5 • Uses Twitter app for authentication • Twitter uses OAuth 1.0a under the hood => secure, hard to implement
  • 28. TWTweetComposeViewController • System dialog for composing an Tweet • Text, Images, URLs • add methods return NO if length exceeds 140 chars • Block based • TWTweetComposeViewControllerCompletionHandler • + (BOOL) canSendTweet;
  • 29. Facebook iOS SDK • Facebook publishes official iOS SDK • https://github.com/facebook/facebook-ios-sdk • Requires Facebook application (web) • Uses official Facebook app for authentication • Alternatively: web authentication, embedded FB authentication dialog • Uses URL scheme handling
  • 31. Why threads? • Slow operations must not block UI • Network operations • Computations • Filesystem operations
  • 32. NSThread • Low level thread abstraction • Requires you to do all the synchronisation manually
  • 33. - (void) detachAsyncOperation { [NSThread detachNewThreadSelector:@selector(operation:) toTarget:self withObject:contextData]; } - (void) operation:(id)contextData { @autorelease { // slow code here // ... [self performSelectorOnMainThread:@selector(updateUI:) withObject:contextData waitUntilDone:NO]; } }
  • 34. GCD • Working with NSThread is difficult • GCD makes an abstraction above threads • C API, functions/macros starting with “dispatch_” prefix
  • 35. Dispatch Queue • Queue of blocks to be performed • FIFO, synchronized • Reference-counted • dispatch_queue_create ➞ dispatch_release • One queue per use-case
  • 36. dispatch_queue_t main_queue = dispatch_get_main_queue() dispatch_queue_t network_queue = dispatch_get_global_queue(priority, 0); // dispatch_queue_t network_queue2 = // dispatch_queue_create("eu.inmite.net", NULL); dispatch_async(network_queue, ^ { // some slow code dispatch_async(main_queue, ^{ // update UI }); // dispatch_release(network_queue2); });
  • 37. Dispatch Semaphore • dispatch_semaphore_create • dispatch_semaphore_wait • dispatch_semaphore_signal
  • 38. NSOperation • Abstraction above “operation” • Meant to be subclassed • main - code to be executed • start - start the operation • cancel - set the cancel flag • Operation priority • Dependencies • [op1 addDependency:op2];
  • 39. NSInvocationOperation • NSOperation subclass • Operation based on target & selector [[NSInvocationOperation alloc] initWithTarget:target selector:selector object:context];
  • 40. NSBlockOperation • NSOperation subclass • Operation based on block [NSBlockOperation blockOperationWithBlock:^{ // some code... }];
  • 41. NSOperationQueue • NSOperations are not meant to be run directly • NSOperationQueue runs the operations correctly • Configurable number of concurrent operations
  • 42. NSOperationQueue NSOperationQueue *queue = [NSOperationQueue mainQueue]; // queue = [NSOperationQueue currentQueue]; // queue = [[NSOperationQueue alloc] init]; [queue addOperation:anOperation];
  • 43. Singleton pattern • Assures access to a shared instance • Usually allows multiple instance creation • Simple pattern, many problems • Threading
  • 44. // within class Foo + (Foo*) getDefault { static Foo *inst = nil; if (!inst) { inst = [[Foo alloc] init]; } return inst; }
  • 45. // within class Foo + (Foo*) getDefault { static Foo *inst = nil; @synchronized (self) { if (!inst) { inst = [[Foo alloc] init]; } } return inst; }
  • 46. // within class Foo + (Foo*) getDefault { static Foo *inst = nil; if (!inst) { // double-check locking @synchronized (self) { if (!inst) { inst = [[Foo alloc] init]; } } } return inst; }
  • 47. // within class Foo + (Foo*) getDefault { static volatile Foo *inst = nil; if (!inst) { // double-check locking @synchronized (self) { if (!inst) { Foo *tmp = [[Foo alloc] init]; OSMemoryBarrier(); inst = tmp; } } } OSMemoryBarrier(); return inst; }
  • 48. // within class Foo + (Foo*) getDefault { static volatile Foo *inst; static dispatch_once_t pred; dispatch_once(&pred, ^ { inst = [[Foo alloc] init]; }); return inst; }
  • 49. Thank you http://www.inmite.eu/talks Petr Dvořák Partner & iOS Development Lead @joshis_tweets