Orange trust badge iOS 参考
使用 Orange trust badge,又称 "Badge de confiance",提供透明信息并使用户对个人信息有更多控制权,帮助用户识别应用是否具有任何敏感功能。
功能
Orange trust badge 显示以下设备权限的处理方式:
- 位置
- 联系人
- 照片库
- 媒体
- 相机
- 日历
- 提醒事项
- 蓝牙共享
- 麦克风
- 语音识别
- 健康
- Homekit
- 运动活跃度 & 健身
它还可以显示以下应用程序数据:
- 通知
- 身份
- 账户信息
- 数据使用
- 广告
- 历史记录
还有以下特点:
- 在 iPhone 和 iPad 上使用 Autolayout(支持 iPad 多任务处理)工作
- 翻译成 2 种语言(英语,法语)
- 用 Swift 5.0 编写但可以在 Objective-C 或基于 Swift 的项目中工作
- API 钩子
- UI 自定义
要求
- iOS 9.0+
- Xcode 10.2.1+
- CocoaPods 1.6.1+
A. 错误追踪器
- 如果您发现任何错误,请通过Github和/或请求合并提交错误报告。
例如项目
在OrangeTrustBadgeDemo项目中提供了集成示例。
安装
嵌入式框架需要最低部署目标为iOS 8
CocoaPods
CocoaPods 是Cocoa项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
CocoaPods 1.0.1+ 是构建 OrangeTrustBadge 所必需的。
要使用CocoaPods将 OrangeTrustBadge 集成到您的Xcode项目中,在您的 Podfile
中指定它
platform :ios, '9.0'
use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'
pod 'OrangeTrustBadge'
在您的 Podfile 的 post_install 指令中配置 OTHER_SWIFT_FLAGS 为 ONLY 您的应用所需的内容。参见 配置 OrangeTrustBage 构建 部分。
例如:如果您的应用需要 HealthKit 权限,请添加以下行
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DHEALTHKIT'
如果不适用,请勿添加。
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DCORELOCATION'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DCONTACTS'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DPHOTOS'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DMEDIAPLAYER'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DCAMERA'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DEVENTKIT'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DBLUETOOTH'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DMICROPHONE'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DSPEECH'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DUSERNOTIFICATIONS'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DMOTION'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DHEALTHKIT'
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DHOMEKIT'
end
end
end
然后,运行以下命令
$ pod install
Carthage
Carthage 是一个去中心化的依赖管理器,它会构建您的依赖关系并提供二进制框架。
您可以使用Homebrew使用以下命令安装Carthage
$ brew update
$ brew install carthage
要使用Carthage将 OrangeTrustBadge 集成到您的Xcode项目中,在您的 Cartfile 中指定它
github "Orange-OpenSource/orange-trust-badge-ios" >= 1.1
运行以下命令以配置和构建框架。将构建好的 OrangeTrustBadge.framework 拖到您的Xcode项目中。
$ carthage update --no-build orange-trust-badge-ios
$ cd Carthage/Checkouts/orange-trust-badge-ios/
$ ./Scripts/configure.sh
$ cd -
$ carthage build orange-trust-badge-ios
配置 OrangeTrustBadge 构建
为了通过 App Store 验证,您必须仅声明应用程序有效使用的权限。否则,苹果公司可能拒绝您的应用程序。
因此,OrangeTrustBadge 通过设置 OTHER_SWIFT_FLAGS 构建设置,仅编译和使用所需的框架。
编译标志 | 框架 | 权限 |
---|---|---|
CORELOCATION | CoreLocation | 位置 |
PHOTOS | 照片 | 照片 |
CONTACTS | 联系人 | 联系人 |
MEDIAPLAYER | MediaPlayer | 媒体 |
CAMERA | MediaPlayer | 相机 |
EVENTKIT | EventKit | 日历、提醒 |
BLUETOOTH | CoreBluetooth | 蓝牙共享 |
MICROPHONE | AVFoundation | 麦克风 |
SPEECH | Speech | 语音识别 |
USERNOTIFICATIONS | UserNotifications | 通知 |
MOTION | CoreMotion | 运动活跃度 & 健身 |
HEALTHKIT | HeakthKit | HealthKit |
HOMEKIT | HomeKit | HomeKit |
配置 Cocoapods 的徽标编译
如果您使用 Cocoapods,则使用 post_install 指令 来配置徽标。请参阅上面的 Cocoapods 部分。
为 Carthage 配置徽标编译
如果您使用 Carthage,OrangeTrustBadge 提供的名为 configure.sh 的脚本将自动配置框架。您在项目的 InfoPlist.strings 文件中定义的内容将被用于以正确的值设置 OTHER_SWIFT_FLAGS 构建设置。
例如:如果您在项目的 InfoPlist.strings 文件中定义了 NSContactsUsageDescription,则 OrangeTrustBadge 将在 OTHER_SWIFT_FLAGS 构建设置中添加 -DCONTACTS
标志。请参阅上面的 Carthage 部分。
下面是您的应用程序 InfoPlist.string 文件的一个示例。
"NSSpeechRecognitionUsageDescription" = "This application has requested access to speech recognition. Speech recognition sends recorded voice to Apple to process your requests.";
"NSAppleMusicUsageDescription" = "This application has requested access to your music activity and your media library.";
"NSBluetoothPeripheralUsageDescription" = "This application has the ability to share data via Bluetooth.";
"NSCalendarsUsageDescription" = "This application can use the calendar information on your device, including consultation of recorded events.";
"NSCameraUsageDescription" = "This application can use the camera of your device. The camera access allows this application to take pictures and record video.";
"NSContactsUsageDescription" = "This application can access, add and / or change your phone contacts.";
"NSHealthShareUsageDescription" = "This application has requested access to your health data.";
"NSHealthUpdateUsageDescription" = "This application has requested access to your health data.";
"NSHomeKitUsageDescription" = "This application has requested access to your home data.";
"NSLocationAlwaysAndWhenInUseUsageDescription" = "With your permission, Location Services allows this application to use information from cellular, Wi-Fi, Global Positioning System (GPS) networks, and Bluetooth to determine your approximate location.";
"NSLocationAlwaysUsageDescription" = "With your permission, Location Services allows this application to use information from cellular, Wi-Fi, Global Positioning System (GPS) networks, and Bluetooth to determine your approximate location.";
"NSLocationWhenInUseUsageDescription" = "With your permission, Location Services allows this application to use information from cellular, Wi-Fi, Global Positioning System (GPS) networks, and Bluetooth to determine your approximate location.";
"NSMicrophoneUsageDescription" = "This application can use the microphone of your device. The access to micro allows the application to record audio content.";
"NSMotionUsageDescription" = "Fitness and health tracking allows apps to access sensor data, including body movement, steps count, and more.";
"NSPhotoLibraryUsageDescription" = "This application can use photos stored on your device. This permission allows the application to read, edit or delete stored files.";
"NSRemindersUsageDescription" = "This application can use the reminders information on your device, including consultation of recorded events.";
就是这样!
用法
SDK的初始化
在Swift中
import OrangeTrustBadge
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
TrustBadge.with(TrustBadgeConfig())
return true
}
或者在Objective-C中
#import "OrangeTrustBadge-Swift.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[TrustBadge with:[[TrustBadgeConfig alloc] init]];
return YES;
}
您创建的TrustBadgeConfig
类实例会在运行时被Orange TrustBadge使用。
请参阅这里的使用方法:[设置TrustBadgeConfig](https://github.com/Orange-OpenSource/orange-trust-badge-ios/blob/master/OrangeTrustBadgeDemo/TrustBadgeIntegration/TrustBadgeConfigurator.swift)
在您的Storyboard中添加OrangeTrustBadge UI
使用iOS 9及以上版本的代码
- 将一个IBAction连接到您的一个界面元素上(例如一个按钮、一个单元格等)。
- 使用以下行实例化OrangeTrustBadge storyboard
模态显示徽章
import OrangeTrustBadge
@IBAction func presentBadge(sender: Any?) {
if let viewController = storyboard.instantiateInitialViewController() as? UISplitViewController {
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true, completion: nil)
// Uncomment this section if you want change the navigationBar Appearance
// and adopt a status bar style (.lightContent or .default)
let navigationController = viewController.viewControllers[0] as! UINavigationController
navigationController.navigationBar.setAppearance(for: UIStatusBarStyle.lightContent)
}
}
推送徽章
import OrangeTrustBadge
@IBAction func pushBadge(sender: Any?) {
let viewController = storyboard.instantiateViewController(withIdentifier: "LandingController")
self.navigationController?.pushViewController(viewController, animated: true)
// Uncomment this section if you want change the navigationBar Appearance
// and adopt a status bar style (.lightContent or .default)
self.navigationController?.navigationBar.setAppearance(for: UIStatusBarStyle.lightContent)
}
设置navigationBar和statusBar的显示效果
extension UINavigationBar {
func setAppearance(for statusBarStyle: UIStatusBarStyle) {
// remove the shadow image at the bottom of the navbar
setBackgroundImage(UIImage(), for: .default)
shadowImage = UIImage()
var darkMode = false
if #available(iOS 12.0, *) {
darkMode = traitCollection.userInterfaceStyle == .dark
}
// for lightContent
switch statusBarStyle {
case .default where darkMode == true:
titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
barTintColor = nil
tintColor = .white
barStyle = .black
case .default:
titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
barTintColor = UIColor(red: 57/255, green: 176/255, blue: 168/255, alpha: 1)
tintColor = .black
barStyle = .default
case .lightContent:
titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
barTintColor = nil
tintColor = .white
barStyle = .black
case .darkContent:
titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
barTintColor = UIColor(red: 57/255, green: 176/255, blue: 168/255, alpha: 1)
tintColor = .black
barStyle = .default
@unknown default:
break
}
}
}
就这样!
使用Storyboard引用(iOS 9及以上版本可用)
- 打开您的Storyboard文件,并在其中添加一个Storyboard引用对象。
- 单击新创建的Storyboard引用,并在右侧面板中的属性检查器中进入
- 在Storyboard字段中,选择
OrangeTrustBadge
- 在Bundle字段中,如果您使用
Cocoapods
进行构建,则输入org.cocoapods.OrangeTrustBadge
,如果您使用Carthage
进行构建,则输入com.orange.omd.OrangeTrustBadge
。 - 最后,从适当的位置创建一个过渡动画,比如按钮或单元格,以接入此Storyboard引用(由于该组件使用UISplitViewController,某些过渡类型可能不可用——尝试使用“模态显示”开启)
就这样!
将自定义视图添加到徽章中
您可能需要在徽章部分添加一些与您的应用相关的信息。橙信托标志允许您提供一个视图控制器,该控制器将作为自定义视图显示。
要提供此视图控制器,您必须实现《TrustBadgeDelegate》协议中的两个方法。
/// If this method returns true, the landing page will displayed a cell that allows to access
//// to this view controller.
@objc optional func shouldDisplayCustomViewController() -> Bool
/// Implement this method to return a viewController to displayed for the CustomMenuCell
@objc optional func viewController(at indexPath: IndexPath) -> UIViewController
为了让用户能够访问您自定义的视图控制器,TrustBadge将在LandingController中添加一个条目。该条目(UITableViewCell)的标题和副标题必须配置以下本机字符串键。
标题
"landing-custom-title" = "可自定义内容";
副标题
"landing-custom-content" = "了解采用Trust徽章的其他应用";
添加本地化支持
为了正确本地化UI,OrangeTrustBadge使用标准的iOS机制。具体来说,除非您的应用支持此本地化,否则SDK将采用用户手机上的当前语言设置。默认情况下,将采用英文。
要添加本地化支持,请转到项目级别,并在“信息”标签中添加适当的本地化。
您可以使用自己的Localizable.strings文件覆盖每个可见文本。有关需要覆盖哪些键的信息,请参阅SDK的本地化文件。
自定义
OrangeTrustBadge可以通过多种方式自定义
主/其他元素视图
在此视图中显示两个预定义部分,显示TrustBadge元素及其底层状态。尽管第一个部分至少需要一个项目是必须的,但您可以使用预定义或自定义元素完全自定义不同的部分。
- 一个自动设置用于常见情况的预定义元素
注意:如果需要,您还可以自定义预定义元素的行为。请确保通过将属性shouldBeAutoConfigured设置为false来禁用自动设置。(例如:aPreDefinedElement.shouldBeAutoConfigured = false)
在Swift中
let advertisingElement = PreDefinedElement(type: .advertising)
advertisingElement.statusClosure = {() in return true}
config.applicationData.append(advertisingElement)
条款和条件查看
在本节中,您可以找到标准化的条款和条件,您可以通过本地化根据您的需求进行替换/更新。如果您想在视图添加一个部分,您只需要添加一个新条款实例。
在Swift中
let customTerm = Term(type: .Custom, titleKey: "term-custom-title", contentKey: "term-custom-content")
config.terms.append(customTerm)
您甚至可以使用.Video TermType显示Dailymotion视频来解释您的政策。请用Dailymotion(例如:x3xwu6v)的视频ID填写"contentKey"。
CSS和HTML标记
TrustBadgeElements和条款描述可能包含HTML代码,但有以下限制
- UTF-8编码
- 不能使用外部资源(图像、CSS等)
当HTML是可选的时,有2种情况
- 完整HTML:您必须提供包含
<html>
和<body>
标签的HTML代码 - 局部HTML:您必须提供不包含
<html>
和<body>
标签的HTML代码
描述应包含名为$$cssStylesheet$$的样式表,并使用h1、h2、p和<span class="p">
格式化文本。您可以通过在应用程序捆绑包中放置名为style.css的文件为OrangeTrustBadge提供自己的CSS文件。
在HTML中
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<style type="text/css">$$cssStylesheet$$</style>
</meta>
</head>
<body>
<h1>Aide</h1>
<p>Si besoin, votre application met à disposition cette adresse mail pour répondre à vos questions :</p>
<span class="p">
<!-- span.p is used for last paragraph, otherwise layount is broken-->
foo.bar@example.com
</span>
</body>
</html>
一些标记将在一段时间后可用,但到目前为止,您只能使用$$applicationName$$,通过使用TrustBadgeConfig的appName字段进行配置(默认:CFBundleDisplayName或CFBundleName的主应用程序)
App Transport Security
除非您在条款部分包含视频,否则OrangeTrustBadge不会在网络上请求任何内容。视频托管在Dailymotion.com,与此服务建立的联系符合ATS策略。
致谢
OrangeTrustBadge 由 Orange 爱心打造
安全披露
如果您相信您已发现 OrangeTrustBadge 的安全漏洞,应尽快在错误跟踪器上报告。
许可证
OrangeTrustBadge 版本版权 (C) 2016 - 2019 Orange
遵循 Apache 许可证 2.0 版本 ("许可证");除非必须在适用法律要求或书面同意下使用此文件,否则不得使用此文件。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明确或隐含的保证或条件。有关许可证对许可权限和限制的具体语言,请参阅许可证。