SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

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
 
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
 

Kürzlich hochgeladen

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
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

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