【发布时间】:2019-01-21 18:29:13
【问题描述】:
我正在尝试实现一个应用程序,它只检测信标并在应用程序处于后台模式时显示通知。
我最初实现了 CBCentralManager 并在 didDiscoverPeripheral 中接收了事件,效果很好,但一旦进入后台模式,它就会停止接收事件。
由于需要后台模式,因此我实现了 CLLocationManager。我在 info.plist 中将 location、background-central 和 background-peripheral 标记为背景模式。我还在 info.plist 中添加了 NSLocationAlwaysUsageDescription、NSLocationAlwaysAndWhenInUseUsageDescription 和 NSLocationWhenInUsageDescription。
相关代码如下:
locMgr = new CLLocationManager();
locMgr.PauseLocationUpdatesAutomatically= false;
locMgr.RequestAlwaysAuthorization();
locMgr.AllowsBackgroundLocationUpdates = true;
var nsuuid = new NSUuid(uuid.ToString());
var nsidentifier = new NSString(identifier);
CLBeaconRegion region = new CLBeaconRegion(nsuuid, nsidentifier);
region.NotifyOnExit = truel
region.NotifyOnEntry = true;
region.NotifyEntryStateOnDisplay = true;
locMgr.StartMonitoring(region);
public void OnRegionEntered(object sender, CLRegionEventARgs e)
{
is there anyway to get advertising info (instance id) of beacon in here?
anything to identify the beacon besides the proximity id which is the same for multiple beacons?
}
我有一个后端服务器,其中包含有关我想调用以获取名称/消息的信标的附加信息。但这是在信标的实例 ID 上键入的。
有人知道在后台模式下获取信标信息的方法吗?我可以连接到外围设备或在 OnRegionEntered 或任何其他方式中设置 cblcentralmanager 吗?
感谢您的帮助!
【问题讨论】:
标签: ios bluetooth-lowenergy ibeacon core-bluetooth beacon