In this presentation, we discuss taking advantage of native iOS features on Titanium both through code and configuration, as well as how to use Apple's toolchain for iOS development to be more productive and produce better products.
Some topics that we'll cover include:
Using Apple's toolchain:
- Debugging app internals
- Custom-configuring plists
- Titanium 'export' and switching to xcode
APIs & Titanium:
- iOS-specific tiapp.xml settings
- App lifecycle on iOS
- View lifecycles & layout
- Memory management 'gotchas'
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’
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
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!
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