测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | 自定义 |
发布上次发布 | 2016年3月 |
SPM支持 SPM | ✗ |
由 Ciaran Hannigan 维护。
此仓库包含 PresenceInsightsSDK 的源码,这是一个 iOS SDK,可轻松集成在Bluemix上可用的 IBM Presence Insights 服务。
此 SDK 支持 iOS 8+。
BLE beacon 传感器 - 监控区域、信标范围,并发送信标通知消息到 PI
管理配置 REST - 指令调用管理配置服务器,以检索有关您的组织信息
设备注册 - 容易将智能手机或平板电脑注册到您的组织。
然后从您的 Carthage/Build/iOS
目录获取 PresenceInsightsSDK.framework
。
如果您正在使用 CocoaPods,请在您的 Podfile
中添加以下代码
use_frameworks!
pod 'PresenceInsightsSDK'
或者,要在 Xcode 中构建框架
PresenceInsightsSDK.xcodeproj
。PresenceInsightsSDK-Universal
目标。输出
文件夹中提取已构建的框架。注意:您在使用此框架之前需要构建它。
要使用框架,只需将 PresenceInsightsSDK.framework 文件拖放到项目目标的 一般 选项卡中的 嵌入式二进制文件 部分。选择“如果需要复制项目”。这将自动将其添加到所有其他必需的位置。然后,要在代码中使用它,添加以下内容
Swift 语言中
import PresenceInsightsSDK
或 Objective-C 语言中
#import <PresenceInsightsSDk/PresenceInsightsSDK.h>
#import <PresenceInsightsSDk/PresenceInsightsSDK-Swift.h>
注意:在 Objective-C 中,您还必须在您的目标构建设置中将“嵌入式内容包含 Swift 代码”设置为“是”。
有两个类承担大部分工作:PIAdapter 和 PIBeaconSensor。
注意:所有示例都将使用 Swift 语言,因为它是首选语言。
首先需要初始化适配器
var piAdapter = PIAdapter(tenant: <tenant>,
org: <org>,
baseURL: "https://presenceinsights.ibmcloud.com"
username: <username>,
password: <password>)
您可以从Bluemix上Presence Insights仪表板中获取您的租户、组织、用户名和密码。(我们更喜欢将它们放入.plist中以方便使用和修改。)
您现在可以从Presence Insights查询各种有用的信息!
piAdapter.getMap(<site code>, floor: <floor code>, callback: {floorMap, error in
// floorMap is of type UIImage
// display it!
})
piAdapter.getAllBeacons(<site code>, floor: <floor code>, callback: {beacons, error in
// beacons is of type [PIBeacon]
// use the x and y coords from each beacon obj to place them on the map.
})
初始化适配器后,您可以初始化一个信标传感器并开始检测信标。
var piBeaconSensor = PIBeaconSensor(adapter: piAdapter)
piBeaconSensor.start()
注意: 要使用PI信标感应,您需要修改Info.plist。添加以下键并设置要显示的消息
这就是让应用程序开始将设备位置发送回您的Presence Insights实例的全部内容。
SDK默认每5秒发送一次您周围信标的信息。如果您想调整这个发送间隔(毫秒),操作非常简单。
piBeaconSensor.setReportInterval(10000)
要停止信标感应
piBeaconSensor.stop()
尽管如此,这个SDK不仅仅能做这些。这里有一些更多您可以使用的功能,以让您的用户享有Presence Insights的好处。
创建PIDevice
var device = PIDevice(name: <your device name>)
device.type = "External" // these values can be found under Settings of your org in the UI
向PIDevice添加加密数据
device.addToDataObject(<Custom Data Object>, key: <Custom Key>)
向PIDevice添加未加密数据
device.addToUnencryptedDataObject(<Custom Data Object>, key: <Custom Key>)
将设备列入黑名单
device.blacklist = true
在PI中注册PIDevice
piAdapter.registerDevice(device, callback: {newDevice, error in
// newDevice is of type PIDevice.
// Do whatever you want with your newDevice here.
})
在PI上更新PIDevice
piAdapter.updateDevice(device, callback: {newDevice, error in
// newDevice is of type PIDevice.
// Do whatever you want with your newDevice here.
})
从PI注销PIDevice
piAdapter.unregisterDevice(device, callback: {newDevice, error in
// newDevice is of type PIDevice.
// Do whatever you want with your newDevice here.
})
获取PI上注册的所有设备列表
piAdapter.getRegisteredDevices({devices, error in
// devices is of type [PIDevice]
// Do whatever you want with the devices array here.
})
从PI获取特定设备
piAdapter.getDeviceByCode(<device code>, callback: {device, error in
// device is of type PIDevice.
// Do whatever you want with your device here.
})
或
piAdapter.getDeviceByDescriptor(<device UUID>, callback: {device, error in
// device is of type PIDevice.
// Do whatever you want with your device here.
})
除了我们自己的用法,我们还公开了多个回调,让您有权按照自己的意愿处理信标事件。
extension <Your class name>: PIBeaconSensorDelegate {
func didRangeBeacons(beacons: [CLBeacon]) {
// Do whatever you want with the ranged beacons here.
}
func didEnterRegion(region: CLRegion) {
// Do something with the region you just entered.
}
func didExitRegion(region: CLRegion) {
// Do something with the region you just exited.
}
}
您还可以使用此SDK(主要是通过不同的方式初始化或修改对象)做其他一些小事情,但这些基础知识应该足以让您开始。祝您玩得开心!
首先,如果事情不起作用,请启用调试以在控制台中查看所有内部操作。
adapter.enableLogging() // adapter is an instance of PIAdapter
我已经启动了信标传感器,但它没有检测到任何信标。可能有两个原因导致这种情况。
当应用程序处于后台或未打开时,我如何发送位置事件?