NearBee 3.2.13

NearBee 3.2.13

ShashankSachin VasRaviSourobrata 维护。



 
依赖
EddystoneScanner>= 0
Socket.IO-Client-Swift= 15.2.0
 

NearBee 3.2.13

  • MobStac Inc.

NearBee iOS SDK

简介

NearBee SDK 是一种通过符合 Eddystone 标准的 BLE 网络实现近距离营销的简单方式。

安装

使用 Cocoapods (推荐)

将以下代码添加到项目的 Podfile 中,我们支持 iOS 10.0+ 请确保您的 pod 设置了正确的平台。

platform :ios, '10.0'
target '<My-App-Target>''
  pod 'NearBee'
end

在项目目录中运行 pod install

手动操作

  1. 在您的系统上下载或克隆此仓库。

  2. 将NearBee.framework文件拖拽至您的Xcode项目。确保已勾选“复制到目标组文件夹”。

  3. NearBee.frameworkEddystoneScanner.frameworkSocket.IO-Client-Swift.framework添加到目标应用的嵌入二进制文件部分。

  4. 在目标应用目标的构建阶段下,在“与库链接”部分添加以下框架:

  • CoreData.framework
  • SystemConfiguration.framework
  • CoreBluetooth.framework
  • CoreLocation.framework
  • EddystoneScanner.framework
  • NearBee.framework
  • Socket.IO-Client-Swift.framework

配置您的项目

  1. 在Info.plist中添加新字段,即NSLocationAlwaysUsageDescriptionNSLocationAlwaysAndWhenInUsageDescriptionNSBluetoothPeripheralUsageDescription,并添加相应的用户展示值。iOS 10及以上版本强制要求此操作。

先决条件

位置

应用应该在设置中照顾到接收通知所需的权限,以便进入信标区域。

蓝牙

应用应该负责开启蓝牙以获取信标的范围。

MY_DEVELOPER_TOKEN

应用应该在初始化SDK时提供开发者令牌。从Beaconstac仪表盘账号页面获取。

MY_ORGANIZATION

应用应该在初始化SDK时提供组织。从Beaconstac仪表盘账号页面获取。

监控区域

如果您使用高级位置管理器的区域监控API,确保它不会影响NearBee SDK。

设置

  1. 在应用的Info.plist中添加以下键和值
    <key>co.nearbee.api_key</key>
    <string>__MY_DEVELOPER_TOKEN__</string>

    <key>co.nearbee.organization_id</key>
    <string>__MY_ORGANIZATION__</string>
  1. 在您的类中导入框架头文件
import NearBee
import <NearBee/NearBee.h>
  1. 使用一行的初始化初始化NearBee,初始化后立即开始扫描信标。
var nearBee = NearBee.initNearBee()
NearBee *nearBee = [NearBee initNearBee];
  1. 如果您希望控制信标的扫描开始和停止
nearBee.startScanning() // Starts scanning for beacons...
nearBee.stopScanning() // Stops scanning for beacons...
[nearBee startScanning];
[nearBee stopScanning];
  1. 实现NearBeeDelegate协议方法,以在UITableViewUICollectionView中显示信标
func onBeaconsFound(_ beacons: [NearBeeBeacon]) {
    // Display Beacons
}
    
func onBeaconsUpdated(_ beacons: [NearBeeBeacon]) {
    // Display Beacons
}
    
func onBeaconsLost(_ beacons: [NearBeeBeacon]) {
    // Display Beacons
}
    
func onError(_ error: Error) {
    // Show Error
}
- (void)onBeaconsUpdated:(NSArray<NearBeeBeacon *> * _Nonnull)beacons {
    // Display Beacons
}

- (void)onBeaconsLost:(NSArray<NearBeeBeacon *> * _Nonnull)beacons {
    // Display Beacons
}

- (void)onBeaconsFound:(NSArray<NearBeeBeacon *> * _Nonnull)beacons {
    // Display Beacons
}

- (void)onError:(NSError * _Nonnull)error {
    // Error
}
  1. 一旦用户点击通知,将其传递给NearBee SDK以显示通知
// In the class where you want to listen to notification events...
let nearBeeInstance = try! NearBee.sharedInstance()
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let isNearBeeNotification = nearBee.checkAndProcessNearbyNotification(response.notification)
    if (isNearBeeNotification) {
        completionHandler()
    } else {
        // Not a near bee notification, you need to handle
    }
}
// In the class where you want to listen to notification events...
NSError *error = nil;
NearBee *nearBeeInstance = [NearBee sharedInstanceAndReturnError:&error];

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
didReceiveNotificationResponse:(UNNotificationResponse *)response 
withCompletionHandler:(void (^)(void))completionHandler {
    
    BOOL isNearBeeNotification = [nearBee checkAndProcessNearbyNotification: response.notification];
    if (isNearBeeNotification) {
        completionHandler()
    } else {
        // Not a near bee notification, you need to handle
    }
}