SlideShare ist ein Scribd-Unternehmen logo
1 von 41
iOS Internals and Best Practices
             Blain Hamon & Max Stepanov
               Senior Software Engineers
                    Appcelerator, Inc.
             @blainhamon @maxstepanov

  bhamon@appcelerator.com mstepanov@appcelerator.com
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
Ti.API.prehistory



                    • 2009: Versions 0.3-0.8

                    • Based on web views

                    • Native via JSON service

                    • Drew upon Ti:Desktop
Ti.API.today



               • 2010+: Versions 0.9+

               • Built-in Interpreters

               • Native via JS callbacks

               • Focused on Mobile
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
App To The Future


•   Native OS




                        Native OS
App To The Future


•   Native OS

•   OS Abstraction Layer




                           OS Abstraction Layer

                                            Native OS
App To The Future


•   Native OS

•   OS Abstraction Layer

•   Ti Binding (Kroll)



                           OS Abstraction Layer     Ti Binding (Kroll)

                                            Native OS
App To The Future


•   Native OS

•   OS Abstraction Layer

•   Ti Binding (Kroll)
                                       Ti Foundation Layer
•   Ti Foundation Layer
                           OS Abstraction Layer     Ti Binding (Kroll)

                                            Native OS
App To The Future


•   Native OS

•   OS Abstraction Layer
                           UI     App     Network       Other Modules…
•   Ti Binding (Kroll)
                                        Ti Foundation Layer
•   Ti Foundation Layer
                           OS Abstraction Layer      Ti Binding (Kroll)
•   Modules
                                            Native OS
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
Game of Threads

                              User taps button
UI-triggered event:
                              User taps button   EventListener
•   UI asynchronously
    triggers event listener

•   UI is ready for more
    action while JS                              EventListener
    processes.
Game of Threads


JS-triggered events:
                                 fireEvent(‘foo’);
•   Still asychronous           setTimeout(0,ƒ());

•   First in, first out queue
                                  EventListener

                                Timeout Function
Game of Threads

                                User taps button
Expensive listeners:            User taps button
                                User taps button   EventListener
•   Still first in, first out

•   Delayed responses


                                                   EventListener




                                                   EventListener
Game of Threads

                            User taps button
Options:                    User taps button
                            User taps button   EventListener
•   Block user              Button covered
    interaction, but only
    as a last resort


                                               EventListener




                                               EventListener
Game of Threads

                            User taps button 1
Options:                    User taps button 2   EventListener 1

•   Block user                                   EventListener 2
    interaction, but only
    as a last resort                             EventListener 1.1

•   Break up expensive                           EventListener 1.2
    listeners
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
My Little Memory


•   In global      held1 = {foo:5};
    namespace
My Little Memory


•   In global           held1 = {foo:5};
    namespace

•   In a closure of a   foo = (function(){
    function               var held2=0;
                           return function()
                              {return held2++;};
                        })();
My Little Memory


•   In global           held1 = {foo:5};
    namespace

•   In a closure of a   foo = (function(){
    function               var held2=0;
                           return function()
•   Property of a
    retained object           {return held2++;};
                        })();

                        foo.bar = held3;
                        foo.add(held4);
My Little Memory


•   In global           held1 = {foo:5};
    namespace

•   In a closure of a   foo = (function(){
    function               var held2=0;
                           return function()
•   Property of a
    retained object           {return held2++;};
                        })();
•   Artificially
    retained via
    Titanium            foo.bar = held3;
                        foo.add(held4);

                        held5.open();
My Little Memory


•   Be aware of      held1 = {foo:5};
    variable scope

•   “nulling out”    foo = (function(){
                        var held2=0;
                        return function()
                           {return held2++;};
                     })();

                     foo.bar = held3;
                     foo.add(held4);

                     held5.open();
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
Class of the Titans


•   Proxies represent
    Titanium objects
                                        Ti Proxy
•   Proxies are
    threadsafe
                            UIView Object     Ti Binding Object   JS Object
•   Proxies store data as
    a native copy
Class of the Titans


•   Proxies represent
    Titanium objects
                                        Ti Proxy
•   Proxies are
    threadsafe
                            UIView Object     Ti Binding Object   JS Object
•   Proxies store data as
    a native copy
                                                   (Method)       JS Object
•   Method objects are
    generated
Class of the Titans


•   Native can be
    expensive
                                        Ti Proxy
•   Cache when possible

•   Use properties          UIView Object     Ti Binding Object   JS Object
    instead of setters

•   Pass properties in                             (Method)       JS Object
    creators

•   Use applyProperties()
iOS Internals


                • History

                • Structure

                • Responsive Apps

                • Memory-Light Apps

                • Fast-Performing Apps

                • Fast-Drawing Apps
Epic View Time



                 • iOS uses OpenGL underneath

                 • Views cache as textures

                 • Opaque textures are faster

                 • Resizing can be expensive

                 • Transparency can be expensive
Epic View Time



                 iOS uses OpenGL underneath
                 • Views cache as textures
                 • Opaque textures are faster
                 • Rendering happens often

                 Some behaviors are expensive
                 • Resizing view sizes
                 • Transparent/views with alpha
                 • Dynamic graphics
Epic View Time
                 var row = Ti.UI.createTableViewRow({
                     height:Ti.UI.SIZE,
                     layout:'horizontal’
                 });
                 row.add(Ti.UI.createImageView({
                     image: myUrl,
                     top: 10,
                     height:89,
                     bottom:11,
                     left: 0,
                     width:125
                 }));
                 row.add(Ti.UI.createLabel({
                     text: myText,
                     left:5,
                     width:Ti.UI.SIZE,
                     height:Ti.UI.SIZE
                 }));
Epic View Time
                 var row = Ti.UI.createTableViewRow({
                     height:Ti.UI.SIZE,
                     layout:'horizontal’
                 });
                 row.add(Ti.UI.createImageView({
                     image: myUrl,
                     top: 10,
                     height:89,
                     bottom:11,
                     left: 0,
                     width:125
                 }));
                 row.add(Ti.UI.createLabel({
                     text: myText,
                     left:5,
                     width:Ti.UI.SIZE,
                     height:Ti.UI.SIZE
                 }));
Epic View Time
                 var row = Ti.UI.createTableViewRow({
                     height:100
                 });
                 row.add(Ti.UI.createImageView({
                     image: myUrl,
                     top: 10,
                     height:89,
                     bottom:11,
                     left: 0,
                     width:125,
                     backgroundColor:'white'
                 }));
                 row.add(Ti.UI.createLabel({
                     text: myText,
                     top:0,
                     left:130,
                     right:0,
                     bottom:0,
                     backgroundColor:'white'
                 });
iOS Internals

                Being responsive:
                • Block UI as last resort
                • Break up expensive tasks

                Being memory-efficient:
                • Mind native object references

                Being fast:
                • Cache when possible
                • Reduce using native containers
                • Concentrate property setting

                Being fast-rendering:
                • Aim for static, opaque views
iOS Debugging
New in Titanium




    Titanium 1.7    Titanium 3.0




   iOS Simulator
                   Physical Devices
Device Debugging

                   • Install with iTunes

                   • Requires network connectivity
                     between development machine
                     and a device

                   • Local WiFi or Hotspot

                   • iPhone Personal Hotspot via
                     WiFi, Bluetooth or USB

                   • Titanium Studio will do the best to
                     locate your device(s)!
Debugging Tips


                           • Turn off Auto-Lock on device



                           • Ensure same WiFi network



                           • Don’t forget to launch your app



    http://docs.appcelerator.com/titanium/3.0/ Debugging on iOS Devices
Game of Threads

                             User taps button 1
                                                  EventListener 1
•   UI thread for handling                            var x = 1;
    user interactions                               Ti.API.log(x);
                                                     openWin(x);
•   JS thread for the        postlayout event
    application logic                              Geo location
                                                    Function         Run
•   Debugger thread for
    communications with                           EventListener 2
    Titanium Studio                                      Line 1
                                                            Line 2
•   Other iOS platform                                      Line 3
    threads
Best Practices


                 • Use conditional breakpoints

                    • A block of JavaScript code

                    • Hit count


                 • Use Console logging with
                   Ti.API functions
Blain Hamon & Max Stepanov
            @blainhamon @maxstepanov

bhamon@appcelerator.com   mstepanov@appcelerator.com

Weitere ähnliche Inhalte

Ähnlich wie Codestrong 2012 breakout session i os internals and best practices

Fred Spencer & Blain Hamon: Advanced Titanium for iOS
Fred Spencer & Blain Hamon: Advanced Titanium for iOSFred Spencer & Blain Hamon: Advanced Titanium for iOS
Fred Spencer & Blain Hamon: Advanced Titanium for iOSAxway Appcelerator
 
Codestrong 2012 breakout session android internals and best practices
Codestrong 2012 breakout session   android internals and best practicesCodestrong 2012 breakout session   android internals and best practices
Codestrong 2012 breakout session android internals and best practicesAxway Appcelerator
 
FAST-NUCES Apps/Games presentation by Husyn 2012
FAST-NUCES Apps/Games presentation by Husyn 2012FAST-NUCES Apps/Games presentation by Husyn 2012
FAST-NUCES Apps/Games presentation by Husyn 2012Hussain Mansoor
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)David Neal
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)slantsixgames
 
Rise of the hybrids
Rise of the hybridsRise of the hybrids
Rise of the hybridsOron Ben Zvi
 
Game object models - Game Engine Architecture
Game object models - Game Engine ArchitectureGame object models - Game Engine Architecture
Game object models - Game Engine ArchitectureShawn Presser
 
Doug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune
 
Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Tomáš Kypta
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]Kuba Břečka
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1Sam Bowne
 
The Reluctant SysAdmin : 360|iDev Austin 2010
The Reluctant SysAdmin : 360|iDev Austin 2010The Reluctant SysAdmin : 360|iDev Austin 2010
The Reluctant SysAdmin : 360|iDev Austin 2010Voxilate
 
CNIT 128 2. Analyzing iOS Applications (Part 1)
CNIT 128 2. Analyzing iOS Applications (Part 1)CNIT 128 2. Analyzing iOS Applications (Part 1)
CNIT 128 2. Analyzing iOS Applications (Part 1)Sam Bowne
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harknessozlael ozlael
 
Brewing Your Own Game Engie eng
Brewing Your Own Game Engie engBrewing Your Own Game Engie eng
Brewing Your Own Game Engie engCoconut Island
 
Overview of python misec - 2-2012
Overview of python   misec - 2-2012Overview of python   misec - 2-2012
Overview of python misec - 2-2012Tazdrumm3r
 

Ähnlich wie Codestrong 2012 breakout session i os internals and best practices (20)

Fred Spencer & Blain Hamon: Advanced Titanium for iOS
Fred Spencer & Blain Hamon: Advanced Titanium for iOSFred Spencer & Blain Hamon: Advanced Titanium for iOS
Fred Spencer & Blain Hamon: Advanced Titanium for iOS
 
Codestrong 2012 breakout session android internals and best practices
Codestrong 2012 breakout session   android internals and best practicesCodestrong 2012 breakout session   android internals and best practices
Codestrong 2012 breakout session android internals and best practices
 
FAST-NUCES Apps/Games presentation by Husyn 2012
FAST-NUCES Apps/Games presentation by Husyn 2012FAST-NUCES Apps/Games presentation by Husyn 2012
FAST-NUCES Apps/Games presentation by Husyn 2012
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)Cross-Platform Desktop Apps with Electron (CodeStock Edition)
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
 
Maximize Your Production Effort (English)
Maximize Your Production Effort (English)Maximize Your Production Effort (English)
Maximize Your Production Effort (English)
 
Rise of the hybrids
Rise of the hybridsRise of the hybrids
Rise of the hybrids
 
Game object models - Game Engine Architecture
Game object models - Game Engine ArchitectureGame object models - Game Engine Architecture
Game object models - Game Engine Architecture
 
Doug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript Projects
 
I say emulate
I say emulateI say emulate
I say emulate
 
Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013Android development - the basics, MFF UK, 2013
Android development - the basics, MFF UK, 2013
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1
 
DjangoSki
DjangoSkiDjangoSki
DjangoSki
 
The Reluctant SysAdmin : 360|iDev Austin 2010
The Reluctant SysAdmin : 360|iDev Austin 2010The Reluctant SysAdmin : 360|iDev Austin 2010
The Reluctant SysAdmin : 360|iDev Austin 2010
 
CNIT 128 2. Analyzing iOS Applications (Part 1)
CNIT 128 2. Analyzing iOS Applications (Part 1)CNIT 128 2. Analyzing iOS Applications (Part 1)
CNIT 128 2. Analyzing iOS Applications (Part 1)
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
 
UNews
UNewsUNews
UNews
 
Brewing Your Own Game Engie eng
Brewing Your Own Game Engie engBrewing Your Own Game Engie eng
Brewing Your Own Game Engie eng
 
Overview of python misec - 2-2012
Overview of python   misec - 2-2012Overview of python   misec - 2-2012
Overview of python misec - 2-2012
 

Mehr von Axway Appcelerator

Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & RoadmapAxway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & RoadmapAxway Appcelerator
 
2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff HaynieAxway Appcelerator
 
Mobile & The New Experience Economy (And What it Means for IT)
Mobile & The New Experience Economy  (And What it Means for IT)Mobile & The New Experience Economy  (And What it Means for IT)
Mobile & The New Experience Economy (And What it Means for IT)Axway Appcelerator
 
Apps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really MeansApps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really MeansAxway Appcelerator
 
Appcelerator Presentation Template
Appcelerator Presentation TemplateAppcelerator Presentation Template
Appcelerator Presentation TemplateAxway Appcelerator
 
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote   jonathan rende, appcelerator's vp of productsCodestrong 2012 keynote   jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jonathan rende, appcelerator's vp of productsAxway Appcelerator
 
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote   jeff haynie, appcelerator's ceoCodestrong 2012 keynote   jeff haynie, appcelerator's ceo
Codestrong 2012 keynote jeff haynie, appcelerator's ceoAxway Appcelerator
 
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 keynote   how to build a top ten appCodestrong 2012 keynote   how to build a top ten app
Codestrong 2012 keynote how to build a top ten appAxway Appcelerator
 
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session  at&t api platform and trendsCodestrong 2012 breakout session  at&t api platform and trends
Codestrong 2012 breakout session at&t api platform and trendsAxway Appcelerator
 
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session   what's new in titanium studioCodestrong 2012 breakout session   what's new in titanium studio
Codestrong 2012 breakout session what's new in titanium studioAxway Appcelerator
 
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session   using appcelerator cloud services in your ...Codestrong 2012 breakout session   using appcelerator cloud services in your ...
Codestrong 2012 breakout session using appcelerator cloud services in your ...Axway Appcelerator
 
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session   the role of cloud services in your next ge...Codestrong 2012 breakout session   the role of cloud services in your next ge...
Codestrong 2012 breakout session the role of cloud services in your next ge...Axway Appcelerator
 
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session   new device platform support for titaniumCodestrong 2012 breakout session   new device platform support for titanium
Codestrong 2012 breakout session new device platform support for titaniumAxway Appcelerator
 
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session   mobile platform and infrastructureCodestrong 2012 breakout session   mobile platform and infrastructure
Codestrong 2012 breakout session mobile platform and infrastructureAxway Appcelerator
 
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session   making money on appcelerator's marketplaceCodestrong 2012 breakout session   making money on appcelerator's marketplace
Codestrong 2012 breakout session making money on appcelerator's marketplaceAxway Appcelerator
 
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session   live multi-platform testingCodestrong 2012 breakout session   live multi-platform testing
Codestrong 2012 breakout session live multi-platform testingAxway Appcelerator
 
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session   leveraging titanium as part of your mobile...Codestrong 2012 breakout session   leveraging titanium as part of your mobile...
Codestrong 2012 breakout session leveraging titanium as part of your mobile...Axway Appcelerator
 
Codestrong 2012 breakout session introduction to mobile web and best practices
Codestrong 2012 breakout session   introduction to mobile web and best practicesCodestrong 2012 breakout session   introduction to mobile web and best practices
Codestrong 2012 breakout session introduction to mobile web and best practicesAxway Appcelerator
 
Codestrong 2012 breakout session how to win bigger mobile deals
Codestrong 2012 breakout session   how to win bigger mobile dealsCodestrong 2012 breakout session   how to win bigger mobile deals
Codestrong 2012 breakout session how to win bigger mobile dealsAxway Appcelerator
 

Mehr von Axway Appcelerator (20)

Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & RoadmapAxway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
 
2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie
 
Making the Mobile Mind Shift
Making the Mobile Mind ShiftMaking the Mobile Mind Shift
Making the Mobile Mind Shift
 
Mobile & The New Experience Economy (And What it Means for IT)
Mobile & The New Experience Economy  (And What it Means for IT)Mobile & The New Experience Economy  (And What it Means for IT)
Mobile & The New Experience Economy (And What it Means for IT)
 
Apps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really MeansApps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really Means
 
Appcelerator Presentation Template
Appcelerator Presentation TemplateAppcelerator Presentation Template
Appcelerator Presentation Template
 
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote   jonathan rende, appcelerator's vp of productsCodestrong 2012 keynote   jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
 
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote   jeff haynie, appcelerator's ceoCodestrong 2012 keynote   jeff haynie, appcelerator's ceo
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
 
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 keynote   how to build a top ten appCodestrong 2012 keynote   how to build a top ten app
Codestrong 2012 keynote how to build a top ten app
 
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session  at&t api platform and trendsCodestrong 2012 breakout session  at&t api platform and trends
Codestrong 2012 breakout session at&t api platform and trends
 
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session   what's new in titanium studioCodestrong 2012 breakout session   what's new in titanium studio
Codestrong 2012 breakout session what's new in titanium studio
 
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session   using appcelerator cloud services in your ...Codestrong 2012 breakout session   using appcelerator cloud services in your ...
Codestrong 2012 breakout session using appcelerator cloud services in your ...
 
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session   the role of cloud services in your next ge...Codestrong 2012 breakout session   the role of cloud services in your next ge...
Codestrong 2012 breakout session the role of cloud services in your next ge...
 
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session   new device platform support for titaniumCodestrong 2012 breakout session   new device platform support for titanium
Codestrong 2012 breakout session new device platform support for titanium
 
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session   mobile platform and infrastructureCodestrong 2012 breakout session   mobile platform and infrastructure
Codestrong 2012 breakout session mobile platform and infrastructure
 
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session   making money on appcelerator's marketplaceCodestrong 2012 breakout session   making money on appcelerator's marketplace
Codestrong 2012 breakout session making money on appcelerator's marketplace
 
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session   live multi-platform testingCodestrong 2012 breakout session   live multi-platform testing
Codestrong 2012 breakout session live multi-platform testing
 
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session   leveraging titanium as part of your mobile...Codestrong 2012 breakout session   leveraging titanium as part of your mobile...
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
 
Codestrong 2012 breakout session introduction to mobile web and best practices
Codestrong 2012 breakout session   introduction to mobile web and best practicesCodestrong 2012 breakout session   introduction to mobile web and best practices
Codestrong 2012 breakout session introduction to mobile web and best practices
 
Codestrong 2012 breakout session how to win bigger mobile deals
Codestrong 2012 breakout session   how to win bigger mobile dealsCodestrong 2012 breakout session   how to win bigger mobile deals
Codestrong 2012 breakout session how to win bigger mobile deals
 

Codestrong 2012 breakout session i os internals and best practices

  • 1. iOS Internals and Best Practices Blain Hamon & Max Stepanov Senior Software Engineers Appcelerator, Inc. @blainhamon @maxstepanov bhamon@appcelerator.com mstepanov@appcelerator.com
  • 2. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 3. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 4. Ti.API.prehistory • 2009: Versions 0.3-0.8 • Based on web views • Native via JSON service • Drew upon Ti:Desktop
  • 5. Ti.API.today • 2010+: Versions 0.9+ • Built-in Interpreters • Native via JS callbacks • Focused on Mobile
  • 6. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 7. App To The Future • Native OS Native OS
  • 8. App To The Future • Native OS • OS Abstraction Layer OS Abstraction Layer Native OS
  • 9. App To The Future • Native OS • OS Abstraction Layer • Ti Binding (Kroll) OS Abstraction Layer Ti Binding (Kroll) Native OS
  • 10. App To The Future • Native OS • OS Abstraction Layer • Ti Binding (Kroll) Ti Foundation Layer • Ti Foundation Layer OS Abstraction Layer Ti Binding (Kroll) Native OS
  • 11. App To The Future • Native OS • OS Abstraction Layer UI App Network Other Modules… • Ti Binding (Kroll) Ti Foundation Layer • Ti Foundation Layer OS Abstraction Layer Ti Binding (Kroll) • Modules Native OS
  • 12. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 13. Game of Threads User taps button UI-triggered event: User taps button EventListener • UI asynchronously triggers event listener • UI is ready for more action while JS EventListener processes.
  • 14. Game of Threads JS-triggered events: fireEvent(‘foo’); • Still asychronous setTimeout(0,ƒ()); • First in, first out queue EventListener Timeout Function
  • 15. Game of Threads User taps button Expensive listeners: User taps button User taps button EventListener • Still first in, first out • Delayed responses EventListener EventListener
  • 16. Game of Threads User taps button Options: User taps button User taps button EventListener • Block user Button covered interaction, but only as a last resort EventListener EventListener
  • 17. Game of Threads User taps button 1 Options: User taps button 2 EventListener 1 • Block user EventListener 2 interaction, but only as a last resort EventListener 1.1 • Break up expensive EventListener 1.2 listeners
  • 18. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 19. My Little Memory • In global held1 = {foo:5}; namespace
  • 20. My Little Memory • In global held1 = {foo:5}; namespace • In a closure of a foo = (function(){ function var held2=0; return function() {return held2++;}; })();
  • 21. My Little Memory • In global held1 = {foo:5}; namespace • In a closure of a foo = (function(){ function var held2=0; return function() • Property of a retained object {return held2++;}; })(); foo.bar = held3; foo.add(held4);
  • 22. My Little Memory • In global held1 = {foo:5}; namespace • In a closure of a foo = (function(){ function var held2=0; return function() • Property of a retained object {return held2++;}; })(); • Artificially retained via Titanium foo.bar = held3; foo.add(held4); held5.open();
  • 23. My Little Memory • Be aware of held1 = {foo:5}; variable scope • “nulling out” foo = (function(){ var held2=0; return function() {return held2++;}; })(); foo.bar = held3; foo.add(held4); held5.open();
  • 24. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 25. Class of the Titans • Proxies represent Titanium objects Ti Proxy • Proxies are threadsafe UIView Object Ti Binding Object JS Object • Proxies store data as a native copy
  • 26. Class of the Titans • Proxies represent Titanium objects Ti Proxy • Proxies are threadsafe UIView Object Ti Binding Object JS Object • Proxies store data as a native copy (Method) JS Object • Method objects are generated
  • 27. Class of the Titans • Native can be expensive Ti Proxy • Cache when possible • Use properties UIView Object Ti Binding Object JS Object instead of setters • Pass properties in (Method) JS Object creators • Use applyProperties()
  • 28. iOS Internals • History • Structure • Responsive Apps • Memory-Light Apps • Fast-Performing Apps • Fast-Drawing Apps
  • 29. Epic View Time • iOS uses OpenGL underneath • Views cache as textures • Opaque textures are faster • Resizing can be expensive • Transparency can be expensive
  • 30. Epic View Time iOS uses OpenGL underneath • Views cache as textures • Opaque textures are faster • Rendering happens often Some behaviors are expensive • Resizing view sizes • Transparent/views with alpha • Dynamic graphics
  • 31. Epic View Time var row = Ti.UI.createTableViewRow({ height:Ti.UI.SIZE, layout:'horizontal’ }); row.add(Ti.UI.createImageView({ image: myUrl, top: 10, height:89, bottom:11, left: 0, width:125 })); row.add(Ti.UI.createLabel({ text: myText, left:5, width:Ti.UI.SIZE, height:Ti.UI.SIZE }));
  • 32. Epic View Time var row = Ti.UI.createTableViewRow({ height:Ti.UI.SIZE, layout:'horizontal’ }); row.add(Ti.UI.createImageView({ image: myUrl, top: 10, height:89, bottom:11, left: 0, width:125 })); row.add(Ti.UI.createLabel({ text: myText, left:5, width:Ti.UI.SIZE, height:Ti.UI.SIZE }));
  • 33. Epic View Time var row = Ti.UI.createTableViewRow({ height:100 }); row.add(Ti.UI.createImageView({ image: myUrl, top: 10, height:89, bottom:11, left: 0, width:125, backgroundColor:'white' })); row.add(Ti.UI.createLabel({ text: myText, top:0, left:130, right:0, bottom:0, backgroundColor:'white' });
  • 34. iOS Internals Being responsive: • Block UI as last resort • Break up expensive tasks Being memory-efficient: • Mind native object references Being fast: • Cache when possible • Reduce using native containers • Concentrate property setting Being fast-rendering: • Aim for static, opaque views
  • 36. New in Titanium Titanium 1.7 Titanium 3.0 iOS Simulator Physical Devices
  • 37. Device Debugging • Install with iTunes • Requires network connectivity between development machine and a device • Local WiFi or Hotspot • iPhone Personal Hotspot via WiFi, Bluetooth or USB • Titanium Studio will do the best to locate your device(s)!
  • 38. Debugging Tips • Turn off Auto-Lock on device • Ensure same WiFi network • Don’t forget to launch your app http://docs.appcelerator.com/titanium/3.0/ Debugging on iOS Devices
  • 39. Game of Threads User taps button 1 EventListener 1 • UI thread for handling  var x = 1; user interactions Ti.API.log(x); openWin(x); • JS thread for the postlayout event application logic Geo location Function Run • Debugger thread for communications with EventListener 2 Titanium Studio  Line 1 Line 2 • Other iOS platform Line 3 threads
  • 40. Best Practices • Use conditional breakpoints • A block of JavaScript code • Hit count • Use Console logging with Ti.API functions
  • 41. Blain Hamon & Max Stepanov @blainhamon @maxstepanov bhamon@appcelerator.com mstepanov@appcelerator.com