扩展您 iOS 应用中的设备和应用程序信息
使用 CocoaPods(iOS 8 及以上):pod 'BBSInspector'
。您需要在想要使用库的每个地方导入 pod,使用 Swift 进行导入
import BBSInspector
只需启用检查器(例如,在 AppDelegate
的 application:didFinishLaunchingWithOptions:
中是个好地方)即可在应用中添加右下角按钮
[...]
window?.makeKeyAndVisible()
[...]
BBSInspector.sharedInstance.enableInspector()
[...]
请注意,在启用检查器之前应该已经调用了窗口的 makeKeyAndVisible
(否则将发生崩溃),如果在使用主板,此行不需要模板,只需在调用 enableInspector
方法之前添加即可。
您可以通过向方法提供 BBSInspectorDataSource
向 BBSInspector 添加自定义信息
let customInspectorDataSource: BBSInspectorDataSource = BBSInspectorDataSource()
customInspectorDataSource.customInspectorInformationItems = {
return [
// Custom BBSInspectorInformation items
]
}
BBSInspector.sharedInstance.dataSource = customInspectorDataSource
基本信息项代表具有标题和描述的数据,触摸检查器中的单元格会将标题复制到剪贴板中。
BBSInspectorInformation(title: "Environment", caption: "PRODUCTION")
可以注册一个操作信息项,当用户点击单元格时执行操作
BBSInspectorInformation(title: "Test information", caption: "Click here to display an alert", captionColor: UIColor.blueColor(), action: { () -> Void in
UIAlertView(title: "Information", message: "Hello, World!", delegate: nil, cancelButtonTitle: "OK").show()
})
一旦计算,数据可以在检查器模态中显示。但是有时候,数据不是静态的,应该重新加载(例如,当到达注册令牌或用户登录时)。
BBSInspector.sharedInstance.reloadInspectorInformation()
如果您的应用程序支持推送通知,您可以设置此数据到 BBSInspectorDataSource
对象。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
BBSInspector.sharedInstance.dataSource.deviceToken = deviceToken
BBSInspector.sharedInstance.reloadInspectorInformation()
}
当更改主窗口的根视图控制器时,底部视图会突然隐藏。运行以下代码确保它返回到前面
BBSInspector.sharedInstance.bringBottomViewToFront()
此组件与 Objective-C 兼容。请注意,您在使用库之前需要导入您的 Swift 头文件
#import "YOUR_PROJECT_NAME-Swift.h"
该项目还需要设置以下构建设置为 “是”
BBSInspector 也支持与 iOS 7 一起使用,但是 CocoaPods 并不支持用于 iOS 7 的 Swift pods。您仍可以将 Library/Classes/
的内容复制到您的项目中或使用 Git 子模块(推荐)。