ti-howtos
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTitanium SDK how-tos
Titanium SDK操作指南
Hands-on guide to Titanium SDK native integrations. Focuses on practical steps, platform differences, and the details that usually bite.
Titanium SDK原生集成实操指南,聚焦实用步骤、平台差异及常见易踩坑细节。
Project detection
项目检测
::::info Auto-detects Titanium projects
This skill detects Titanium projects automatically.
Indicators:
- exists (definitive)
tiapp.xml - Alloy project: folder
app/ - Classic project: folder
Resources/
Behavior:
- Titanium detected: provide native integration guidance, permissions, modules, and platform notes
- Not detected: say this skill is for Titanium projects only ::::
::::info 自动检测Titanium项目
本技能可自动检测Titanium项目。
检测标识:
- 存在文件(确定性标识)
tiapp.xml - Alloy项目:包含文件夹
app/ - 经典项目:包含文件夹
Resources/
行为逻辑:
- 检测到Titanium项目:提供原生集成指导、权限配置、模块依赖及平台注意事项
- 未检测到:提示本技能仅适用于Titanium项目 ::::
Integration workflow
集成流程
- Requirement check: permissions, , and module dependencies.
tiapp.xml - Service setup: listeners and services (Location, Push, Core Motion, and so on).
- Lifecycle sync: tie listeners to Android and iOS lifecycle events.
- Error handling: use robust callbacks for async native calls.
- Platform optimization: apply platform-specific logic (Intent filters, Spotlight, Core Motion).
- 需求检查:权限、配置及模块依赖。
tiapp.xml - 服务设置:监听器与服务配置(定位、推送、Core Motion等)。
- 生命周期同步:将监听器与Android和iOS的生命周期事件绑定。
- 错误处理:为异步原生调用添加健壮的回调逻辑。
- 平台优化:应用平台特定逻辑(Intent过滤器、Spotlight、Core Motion等)。
Native integration rules
原生集成规则
iOS permissions
iOS权限配置
- Location: or
NSLocationWhenInUseUsageDescriptioninNSLocationAlwaysAndWhenInUseUsageDescription.tiapp.xml - Motion activity: required for Core Motion Activity API.
- Camera and photo: and
NSCameraUsageDescription.NSPhotoLibraryUsageDescription - Background modes: required for background audio, location, or VOIP.
- iOS 17+: add for UserDefaults and File Timestamps.
PrivacyInfo.xcprivacy
- 定位:在中添加
tiapp.xml或NSLocationWhenInUseUsageDescription。NSLocationAlwaysAndWhenInUseUsageDescription - 运动活动:使用Core Motion Activity API时需配置。
- 相机与相册:添加和
NSCameraUsageDescription。NSPhotoLibraryUsageDescription - 后台模式:后台音频、定位或VOIP功能需配置。
- iOS 17+:为UserDefaults和文件时间戳添加配置。
PrivacyInfo.xcprivacy
Android resource management
Android资源管理
- Services: stop background services when they are no longer needed.
- Location: use and FusedLocationProvider (requires
distanceFilter).ti.playservices - Intents: set action, data type, and category. Copy the root activity to for intent filters.
tiapp.xml
- 服务:不再需要时停止后台服务。
- 定位:使用和FusedLocationProvider(需依赖
distanceFilter模块)。ti.playservices - Intents:设置action、数据类型及category。复制根Activity到以配置Intent过滤器。
tiapp.xml
Data and networking
数据与网络
- HTTPClient: handle both and
onload.onerror - SQLite: close both and
dbto avoid locks.resultSet - Filesystem: check before using SD card storage.
isExternalStoragePresent() - Binary data: use and
Ti.Bufferfor byte-level work.Ti.Codec - Streams: use ,
BufferStream, orFileStreamfor chunked I/O.BlobStream
- HTTPClient:同时处理和
onload事件。onerror - SQLite:关闭和
db以避免锁表。resultSet - 文件系统:使用SD卡存储前先检查。
isExternalStoragePresent() - 二进制数据:使用和
Ti.Buffer处理字节级操作。Ti.Codec - 流:使用、
BufferStream或FileStream处理分块I/O。BlobStream
Media and memory
媒体与内存
- Camera and gallery: use to reduce memory pressure.
imageAsResized - Audio: handle and
pausefor streaming interruptions.resume - WebView: avoid TableView embedding; set if needed.
touchEnabled=false - Video: Android requires fullscreen; iOS supports embedded players.
- 相机与相册:使用减少内存压力。
imageAsResized - 音频:处理流中断时的和
pause逻辑。resume - WebView:避免嵌入TableView;必要时设置。
touchEnabled=false - 视频:Android要求全屏播放;iOS支持嵌入式播放器。
Platform-specific properties
平台特定属性
::::danger Platform-specific properties need modifiers
Using or without platform modifiers can break cross-platform builds.
Ti.UI.iOS.*Ti.UI.Android.*Bad example:
javascript
// Wrong: adds Ti.UI.iOS to Android build
const win = Ti.UI.createWindow({
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
});Good options:
TSS modifier (Alloy):
tss
"#mainWindow[platform=ios]": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}Conditional code:
javascript
if (OS_IOS) {
$.mainWindow.statusBarStyle = Ti.UI.iOS.StatusBar.LIGHT_CONTENT;
}Always require modifiers:
- iOS: ,
statusBarStyle,modalStyle, anymodalTransitionStyle.Ti.UI.iOS.* - Android: config, any
actionBarconstant.Ti.UI.Android.*
For TSS platform modifiers, see the code conventions in or the platform UI guides in .
::::
skills/ti-expert/references/code-conventions.md#platform--device-modifiersreferences/ios-platform-deep-dives.md::::danger 平台特定属性需添加修饰符
未添加平台修饰符直接使用或会破坏跨平台构建。
Ti.UI.iOS.*Ti.UI.Android.*错误示例:
javascript
// 错误:会在Android构建中引入Ti.UI.iOS代码
const win = Ti.UI.createWindow({
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
});正确方案:
TSS修饰符(Alloy框架):
tss
"#mainWindow[platform=ios]": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}条件判断代码:
javascript
if (OS_IOS) {
$.mainWindow.statusBarStyle = Ti.UI.iOS.StatusBar.LIGHT_CONTENT;
}必须添加修饰符的属性:
- iOS:、
statusBarStyle、modalStyle及所有modalTransitionStyle属性。Ti.UI.iOS.* - Android:配置及所有
actionBar常量。Ti.UI.Android.*
关于TSS平台修饰符的更多内容,请参考中的代码规范,或中的平台UI指南。
::::
skills/ti-expert/references/code-conventions.md#platform--device-modifiersreferences/ios-platform-deep-dives.mdReference guides
参考指南
Core features
核心功能
- Location and maps: GPS tracking and battery-efficient location rules.
- Google Maps v2 (Android): API keys, Google Play Services, and v2 features.
- iOS Map Kit: 3D camera, system buttons, and iOS callouts.
- Notification services: push notifications (APNs/FCM), local alerts, interactive notifications.
- 定位与地图:GPS追踪及省电定位规则。
- Google Maps v2(Android):API密钥、Google Play Services及v2版本特性。
- iOS Map Kit:3D相机、系统按钮及iOS标注框。
- 通知服务:推送通知(APNs/FCM)、本地提醒、交互式通知。
Data handling
数据处理
- Remote data sources: HTTPClient lifecycle, JSON/XML parsing, uploads, downloads, sockets, SOAP, SSL.
- Local data sources: filesystem operations, SQLite, Properties API, persistence strategy.
- Buffer, Codec, and Streams: binary data manipulation and serial data flows.
- 远程数据源:HTTPClient生命周期、JSON/XML解析、上传下载、套接字、SOAP、SSL。
- 本地数据源:文件系统操作、SQLite、Properties API、持久化策略。
- Buffer、Codec与流:二进制数据处理及串行数据流。
Media and content
媒体与内容
- Media APIs: audio playback and recording, video streaming, camera and gallery, ImageViews, density assets.
- 媒体API:音频播放与录制、视频流、相机与相册、ImageView、适配不同密度的资源。
Web integration
Web集成
- Web content integration: WebView (WKWebView), local and remote content, bidirectional communication.
- Webpack build pipeline: Ti 9.1.0+ build pipeline, npm integration, and the alias.
@
- Web内容集成:WebView(WKWebView)、本地与远程内容、双向通信。
- Webpack构建流水线:Ti 9.1.0+构建流水线、npm集成及别名。
@
Platform-specific (Android)
平台特定(Android)
- Android platform deep dives: intents, intent filters, broadcast permissions, background services.
- Android平台深度解析:Intents、Intent过滤器、广播权限、后台服务。
Platform-specific (iOS)
平台特定(iOS)
- iOS platform deep dives: iOS 17 privacy, silent push, Spotlight, Handoff, iCloud, Core Motion, WatchKit and Siri.
- iOS平台深度解析:iOS 17隐私政策、静默推送、Spotlight、Handoff、iCloud、Core Motion、WatchKit与Siri。
Advanced and DevOps
进阶与DevOps
- Extending Titanium: Hyperloop, native modules (Proxy and View), Xcode debugging, AndroidX migration for SDK 9.0.
- Debugging and profiling: memory management, leak detection, native tools.
- Automation (Fastlane and Appium): CI/CD, UI testing, store deployment.
- 扩展Titanium:Hyperloop、原生模块(Proxy与View)、Xcode调试、SDK 9.0的AndroidX迁移。
- 调试与性能分析:内存管理、内存泄漏检测、原生工具。
- 自动化(Fastlane与Appium):CI/CD、UI测试、应用商店部署。
Related skills
相关技能
For tasks beyond native feature integration, use:
| Task | Use this skill |
|---|---|
| Project architecture, services, memory cleanup | |
| UI layouts, ListViews, gestures, animations | |
| Hyperloop, app distribution, tiapp.xml config | |
| Alloy MVC, models, data binding | |
若需处理原生功能集成之外的任务,请使用以下技能:
| 任务 | 对应技能 |
|---|---|
| 项目架构、服务、内存清理 | |
| UI布局、ListView、手势、动画 | |
| Hyperloop、应用分发、tiapp.xml配置 | |
| Alloy MVC、模型、数据绑定 | |
Response format
响应格式
- Prerequisites: required permissions, config, or modules.
tiapp.xml - Step-by-step implementation: task-focused code guide with error handling.
- Platform caveats: iOS and Android differences.
- Best practices: memory, lifecycle, and performance tips.
- 前置条件:所需权限、配置或依赖模块。
tiapp.xml - 分步实现:以任务为核心的代码指南,包含错误处理。
- 平台注意事项:iOS与Android的差异。
- 最佳实践:内存、生命周期及性能优化建议。