我想使用我的 swift ios 应用程序使用谷歌附近的 api(不是 iBeacon api)扫描信标
我看到了 Google 开发者文档,并从同一个站点获取了 git 示例。
这是我的代码
我第一次在真正的 ios 设备上安装了该应用程序
但是永远不会调用found
and处理程序。lost
我仔细检查了捆绑 ID,公共 ios API 密钥(信标附件的相同谷歌控制台项目)
但它仍然无法在工作和注册的信标附近工作。
我也有一个成功扫描同一个信标的安卓应用程序。
我还能检查什么?
我的快速代码中缺少"Strategy"
这段代码。
我怎样才能添加这个?为什么 github 示例中缺少此内容?
GNSStrategy *beaconStrategy = [GNSStrategy
strategyWithParamsBlock:^(GNSStrategyParams *params) {
params.includeBLEBeacons = YES;
}];
GNSSubscriptionParams *beaconParams = [GNSSubscriptionParams
paramsWithMessageNamespace:@"com.mycompany.mybeaconservice"
type:@"mybeacontype"
strategy:beaconStrategy];
_beaconSubscription = [_messageManager subscriptionWithParams:beaconParams
messageFoundHandler:myMessageFoundHandler
messageLostHandler:myMessageLostHandler];
在我的代码中:
func startScanning() {
if let messageMgr = self.messageMgr {
// Subscribe to messages from nearby devices and display them in the message view.
subscription = messageMgr.subscriptionWithMessageFoundHandler({[unowned self] (message: GNSMessage!) -> Void in
self.mainViewController.location_text.text = (String(data: message.content, encoding:NSUTF8StringEncoding))
self.mainViewController.startRefreshTimer()
},
messageLostHandler: {[unowned self](message: GNSMessage!) -> Void in
if (self.mainViewController.userState.enrollState == EnrollState.confirmPosition)
{
self.mainViewController.stopRefreshTimer()
self.mainViewController.enrollButtonManager.setSearchingForBeaconsBtn()
}
})
}
}