OneSky Over-The-Air Plugin for iOS
使用 OneSky 为您的 iOS 应用提供空中对空翻译更新。
注意:此插件仅支持 .strings
文件。
安装
下载 OneSkyOTAPlugin.framework
- 从发行标签下载
OneSkyOTAPlugin.zip
并将其拖到 项目导航器 的 框架 部分中。 - 在目标的 构建设置 中,将
-ObjC
添加到 其他链接器标志 设置。
CocoaPods
pod 'OneSkyOTAPlugin', '~> 0.9.13'
集成
导入库头文件
#import <OneSkyOTAPlugin/OneSkyOTAPlugin.h>
将以下代码添加到您的AppDelegate中的 -application:didFinishLaunchingWithOptions:
部分
[OneSkyOTAPlugin provideAPIKey:ONESKY_API_KEY
APISecret:ONESKY_API_SECRET
projectID:ONESKY_PROJECT_ID];
[OneSkyOTAPlugin checkForUpdate];
可选:在 - (void)applicationDidBecomeActive:(UIApplication*)application
中添加 [OneSkyOTAPlugin checkForUpdate]
ONESKY_API_KEY
和 ONESKY_API_SECRET
可在 OneSky Web Admin 下的 API Keys & Usage 中的 Site Settings 找到。 ONESKY_PROJECT_ID
可在 All Projects 页面找到。
注意:必须在调用 -checkForUpdate
之前设置以上参数。
安全
出于安全考虑,您可能不想在应用程序的源代码中嵌入API密钥,在这种情况下,可以通过将字符串输出API隐私设置为公开来跳过API密钥,前往“项目设置 > 隐私 > 字符串输出API”以了解更多信息。
[OneSkyOTAPlugin provideAPIKey:ONESKY_API_KEY
APISecret:nil
projectID:ONESKY_PROJECT_ID];
使用
只需将 NSLocalizedString
替换为 OSLocalizedString
,如果OneSky上找不到字符串翻译,插件将回退到本地的.strings文件。
OSLocalizedString(key, comment)
OSLocalizedStringFromTable(key, tbl, comment)
OSLocalizedStringWithDefaultValue(key, tbl, val, comment)
Swift 3
您可以在Swift中公开函数来包装代码
public func OSLocalizedString(_ key: String, comment: String) -> String {
return OneSkyOTAPlugin.localizedString(forKey: key, value: "", table: nil)
}
public func OSLocalizedStringFromTable(_ key: String, table: String, comment: String) -> String {
return OneSkyOTAPlugin.localizedString(forKey: key, value: "", table: table)
}
语言
插件默认使用的语言是 -[[NSLocale preferredLanguages] firstObject]
。如果您的应用程序实现了自定义语言逻辑,您可以使用新API设置语言。
[OneSkyOTAPlugin setLanguage:@"pt-PT"];
界面构建者支持
该插件也支持 界面构建者 文件(.xib
和 .stroyboard
)的 OTA 翻译,翻译将在 -[UIView awakeFromNib]
中自动设置。要启用 界面构建者 支持,在 项目编辑器
中为您的应用目标添加一个 运行脚本构建阶段
,将以下脚本复制并粘贴到脚本区域。
OneSkyOTAPlugin.framework
./OneSkyOTAPlugin.framework/ibsupport
CocoaPods
./Pods/OneSkyOTAPlugin/OneSkyOTAPlugin/ibsupport