SlideShare a Scribd company logo
1 of 29
Advanced	
  Titanium	
  iOS	
  


Fred	
  Spencer	
  &	
  Blain	
  Hamon	
  
About Blain
•  iOS Platform Engineer, Platform
  Engineering

•  Titanium Mobile Core Contributor
   •    Origin developer

   •    Memory architecture

•  Longtime Objective-C
  programmer; MacOS and iOS

•  Daily Tools: Gity, Instruments,
  Terminal, TextWrangler, Xcode
About Fred
•  Senior Application Architect,
  Professional Services

•  Titanium Mobile Core Contributor
•  Digital Media Instructor, RISD
  Continuing Education

•  Lead architect, Late Night with
  Jimmy Fallon iPhone / Android,
  NBC iPad; client apps

•  Daily Tools: TextMate, Terminal,
  Xcode, Tower (git)
What we’ll cover

•  iOS and Titanium
  lifecycles

•  Titanium memory
  management

•  Custom build options

•  Debugging your apps

•  Titanium ‘export’
iOS and Titanium
   Lifecycles
Application Lifecycle
               App.js
Start
               loads              Standard
                                  Run Loop            pause
                                  (Focused)


               resume
                                      resumed       Standard
                                                    Run Loop
                                                    (Blurred)

     App is
    unloaded            No code
                        running
                                                Background
                                                 JavaScript
                                                runs briefly
Main/UI           Background
iOS & Ti Events                   Thread             JS Thread
                                   Click

•  Event listener callbacks are    Focus                  Click
  done asynchronously                                    Handler
                                  SetLeft
                                                     fireEvent
•  UI runs on main thread,
                                            Size fetch
  and does not wait for
  JavaScript
                                                          Focus
•  JavaScript runs in a                                  Handler

  separate background
                                                           App
  thread, and may wait on UI                              Event
                                                         Handler
Titanium Memory
   Management
How it works

•  JS uses garbage collection, Native uses retain count

•  Kroll objects are JS & Native objects bridging the gap


       Native Objects                          JavaScript Objects

 NSObject
   NSObject                                        JS object
      NSObject                                        JS object
                                                         JS object
           TiProxy         KrollObject pair                 JS object


  UIView
                                                            JS Listener
                 KrollCallback
                                          JS ƒ()
An object will hang around if…

•  …it’s referenced directly

•  …it’s a property of another object

•  …it’s being intentionally kept by
  native elements
   •  i.e. Window is open, PopOver
      is shown
Circular reference
•  The JavaScript engine is unaware of native relationships

•  Does not effect functions added with addEventListener


        Native Objects                         JavaScript Objects

                                     LEAKY Closure            OK Closure
   TiProxy
                         KrollObject pair                     JS object

                                            JS ƒ()                JS ƒ()
       KrollCallback

                                                     OK Closure
   TiProxy               KrollObject pair
                                                          JS Listener
Prevent leaks by avoiding…

•  Closures that bind to
  Titanium proxies

•  Extending Titanium object prototypes

•  Passing references from one closure to another, without
  keeping track of the reference trail – null the past!
Deep dive @CODESTRONG:



Your Apps are Leaking - Controlling
          Memory Leaks

        Today, 5:20 – 6:00 PM


           Rick Blalock
Common PS Patterns

•  Heavily influenced by product requirements

•  Most Common
   •  Module/Revealing Module, Factory

•  Upcoming
   •  CommonJS ‘require’ modules
Custom Build
  Options
tiapp.xml and Info.plist

•  Allows customization of project build options

•  tiapp.xml => Info.plist mapping, but not everything

•  How do you know what’s available?
   •  [path to Titanium sdk]/tiapp.py

   •  Search ‘def parse_iphone’

•  Custom Info.plist is merged with tiapp.xml, on
  project build
What to know (tiapp.xml)

•  Use the <iphone> tag to separate from generic and
  android build options

•  Orientation options should be broken out by device
  type, ‘iphone’ or ‘ipad’
                  <orientations device=“ipad”>

•  The platform tag attribute will ensure the correct
  platform-specific module will be used
            <module platform=“iphone” version=“1.0”>
What to know (Info.plist)

•  Place in your project’s root folder

•  Custom fonts use the the UIAppFonts key and array
  tags, with nested string tags - font files are placed in
  project’s ‘Resources’ folder
                     <key>UIAppFonts</key>

•  Custom URL schemes can be registered to allow for
  opening of app from other apps and mobile Safari
                <key>CFBundleURLSchemes</key>
Tip: If your tiapp.xml and custom
Info.plist changes aren’t being picked up,
   dump the contents of the project’s
   ‘build/iphone’ folder and re-build.



   You may also need to do this when
changing between Titanium SDK versions.
Titanium
‘export’
What is and why use it?

•  Bundles all resources into an exportable Xcode project

•  Python script (1.8.0 feature; TiStudio, late 2011)
   •  [path to Titanium SDK]/iphone/transport.py

   •  transport.py [path of Titanium project]

•  Share and collaborate on projects with those who have
  not installed the Titanium SDK

•  Consistent entry point for GDB debugging

•  Per Project-based, Objective-C customization
Debugging
Your Apps
GDB and Titanium Studio Debugging

•  Install Firefox/IE (JS)

•  More easily debug both high-level
  JavaScript and low-level internals

•  Excellent for effective
  module development and
  Titanium Export
DEMO
Questions?
Resources
Resources : Custom Build Options

•  appc.me/ti-tiapp-doc

•  appc.me/apple-info-plist-doc

•  appc.me/apple-info-plist-fonts

•  appc.me/apple-config-common-app-behavior

•  appc.me/custom-url-schemes

•  appc.me/apple-register-file-types
Resources : Other

•  Memory
   •  appc.me/javascript-memory-management

•  Debugging
   •  appc.me/debugging-mobile-applications

   •  appc.me/apple-debug-gdb

More Related Content

Similar to 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
Axway Appcelerator
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
Will Iverson
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
Andrew Ferrier
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
housecor
 

Similar to Fred Spencer & Blain Hamon: Advanced Titanium for iOS (20)

Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
 
Node.JS briefly introduced
Node.JS briefly introducedNode.JS briefly introduced
Node.JS briefly introduced
 
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
 
Dan Haywood
Dan HaywoodDan Haywood
Dan Haywood
 
Ios development
Ios developmentIos development
Ios development
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 
SeaJUG May 2012 mybatis
SeaJUG May 2012 mybatisSeaJUG May 2012 mybatis
SeaJUG May 2012 mybatis
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
Method Swizzling with Objective-C
Method Swizzling with Objective-CMethod Swizzling with Objective-C
Method Swizzling with Objective-C
 
Spring session
Spring sessionSpring session
Spring session
 
Building Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on AzureBuilding Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on Azure
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
 
Kirin - Making Single Page Web Apps with a Native UI
Kirin - Making Single Page Web Apps with a Native UIKirin - Making Single Page Web Apps with a Native UI
Kirin - Making Single Page Web Apps with a Native UI
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Working and Features of HTML5 and PhoneGap - An Overview
Working and Features of HTML5 and PhoneGap - An OverviewWorking and Features of HTML5 and PhoneGap - An Overview
Working and Features of HTML5 and PhoneGap - An Overview
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid Does
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 

More from Axway 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 products
Axway 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 ceo
Axway 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 app
Axway 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 trends
Axway 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 studio
Axway 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 titanium
Axway 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 infrastructure
Axway 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 marketplace
Axway 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 testing
Axway 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 practices
Axway Appcelerator
 

More from 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
 
Stop Debating, Start Measuring
Stop Debating, Start MeasuringStop Debating, Start Measuring
Stop Debating, Start Measuring
 
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
 

Recently uploaded

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
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
"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 ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
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 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Fred Spencer & Blain Hamon: Advanced Titanium for iOS

  • 1. Advanced  Titanium  iOS   Fred  Spencer  &  Blain  Hamon  
  • 2. About Blain •  iOS Platform Engineer, Platform Engineering •  Titanium Mobile Core Contributor •  Origin developer •  Memory architecture •  Longtime Objective-C programmer; MacOS and iOS •  Daily Tools: Gity, Instruments, Terminal, TextWrangler, Xcode
  • 3. About Fred •  Senior Application Architect, Professional Services •  Titanium Mobile Core Contributor •  Digital Media Instructor, RISD Continuing Education •  Lead architect, Late Night with Jimmy Fallon iPhone / Android, NBC iPad; client apps •  Daily Tools: TextMate, Terminal, Xcode, Tower (git)
  • 4. What we’ll cover •  iOS and Titanium lifecycles •  Titanium memory management •  Custom build options •  Debugging your apps •  Titanium ‘export’
  • 5. iOS and Titanium Lifecycles
  • 6. Application Lifecycle App.js Start loads Standard Run Loop pause (Focused) resume resumed Standard Run Loop (Blurred) App is unloaded No code running Background JavaScript runs briefly
  • 7. Main/UI Background iOS & Ti Events Thread JS Thread Click •  Event listener callbacks are Focus Click done asynchronously Handler SetLeft fireEvent •  UI runs on main thread, Size fetch and does not wait for JavaScript Focus •  JavaScript runs in a Handler separate background App thread, and may wait on UI Event Handler
  • 8. Titanium Memory Management
  • 9. How it works •  JS uses garbage collection, Native uses retain count •  Kroll objects are JS & Native objects bridging the gap Native Objects JavaScript Objects NSObject NSObject JS object NSObject JS object JS object TiProxy KrollObject pair JS object UIView JS Listener KrollCallback JS ƒ()
  • 10. An object will hang around if… •  …it’s referenced directly •  …it’s a property of another object •  …it’s being intentionally kept by native elements •  i.e. Window is open, PopOver is shown
  • 11. Circular reference •  The JavaScript engine is unaware of native relationships •  Does not effect functions added with addEventListener Native Objects JavaScript Objects LEAKY Closure OK Closure TiProxy KrollObject pair JS object JS ƒ() JS ƒ() KrollCallback OK Closure TiProxy KrollObject pair JS Listener
  • 12. Prevent leaks by avoiding… •  Closures that bind to Titanium proxies •  Extending Titanium object prototypes •  Passing references from one closure to another, without keeping track of the reference trail – null the past!
  • 13. Deep dive @CODESTRONG: Your Apps are Leaking - Controlling Memory Leaks Today, 5:20 – 6:00 PM Rick Blalock
  • 14. Common PS Patterns •  Heavily influenced by product requirements •  Most Common •  Module/Revealing Module, Factory •  Upcoming •  CommonJS ‘require’ modules
  • 15. Custom Build Options
  • 16. tiapp.xml and Info.plist •  Allows customization of project build options •  tiapp.xml => Info.plist mapping, but not everything •  How do you know what’s available? •  [path to Titanium sdk]/tiapp.py •  Search ‘def parse_iphone’ •  Custom Info.plist is merged with tiapp.xml, on project build
  • 17. What to know (tiapp.xml) •  Use the <iphone> tag to separate from generic and android build options •  Orientation options should be broken out by device type, ‘iphone’ or ‘ipad’ <orientations device=“ipad”> •  The platform tag attribute will ensure the correct platform-specific module will be used <module platform=“iphone” version=“1.0”>
  • 18. What to know (Info.plist) •  Place in your project’s root folder •  Custom fonts use the the UIAppFonts key and array tags, with nested string tags - font files are placed in project’s ‘Resources’ folder <key>UIAppFonts</key> •  Custom URL schemes can be registered to allow for opening of app from other apps and mobile Safari <key>CFBundleURLSchemes</key>
  • 19. Tip: If your tiapp.xml and custom Info.plist changes aren’t being picked up, dump the contents of the project’s ‘build/iphone’ folder and re-build. You may also need to do this when changing between Titanium SDK versions.
  • 21. What is and why use it? •  Bundles all resources into an exportable Xcode project •  Python script (1.8.0 feature; TiStudio, late 2011) •  [path to Titanium SDK]/iphone/transport.py •  transport.py [path of Titanium project] •  Share and collaborate on projects with those who have not installed the Titanium SDK •  Consistent entry point for GDB debugging •  Per Project-based, Objective-C customization
  • 23. GDB and Titanium Studio Debugging •  Install Firefox/IE (JS) •  More easily debug both high-level JavaScript and low-level internals •  Excellent for effective module development and Titanium Export
  • 24. DEMO
  • 26.
  • 28. Resources : Custom Build Options •  appc.me/ti-tiapp-doc •  appc.me/apple-info-plist-doc •  appc.me/apple-info-plist-fonts •  appc.me/apple-config-common-app-behavior •  appc.me/custom-url-schemes •  appc.me/apple-register-file-types
  • 29. Resources : Other •  Memory •  appc.me/javascript-memory-management •  Debugging •  appc.me/debugging-mobile-applications •  appc.me/apple-debug-gdb