问题描述
因此,我一直在努力检测办公室中可用的 iBeacon。我上网冲浪,总能找到一个解决方案,您需要知道 iBeacons 的 UUID 才能检测到它。但是,我在 github 上发现了这个(向这个人大喊大叫)。我在办公室运行了这个应用程序,它能够检测到 2 个可用的 iBeacons(其中 1 个具有动态 UUID),但它是用目标 C 编写的。
在目标 c 上,它怎么可能检测到周围的 iBeacons 而 Swift 不能?
我猜这是开始扫描 iBeacon 的 Objective C
代码(我之前从未学过 obj c):
AIBBeaconRegionAny *beaconRegionAny = [[AIBBeaconRegionAny alloc] initWithIdentifier:@"Any"];
[self.locationManager startRangingBeaconsInRegion:beaconRegionAny];
这是我在 Swift 中的代码:
locationManager?.startRangingBeacons(satisfying: CLBeaconIdentityConstraint(uuid: UUID(uuidString: "Any")!,major: 9,minor: 2)).
好吧,它当然崩溃了,我也将其更改为 "11111111-1111-1111-1111-111111111111"
并打印了信标,但没有找到。
谁能解释一下我错过了什么?或者现在真的有可能吗?
提前致谢
更新:
还有 AIBBeaconRegionAny
可以检测任何信标。
文件AIBBeaconRegionAny.h
:
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface AIBBeaconRegionAny : CLBeaconRegion
- (id)initWithIdentifier:(Nsstring *)identifier;
@end
文件AIBBeaconRegionAny.m
:
#import "AIBBeaconRegionAny.h"
// https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/CoreLocation.framework/CLRegion.h
struct ClientRegion {
BOOL identifier[512];
BOOL onBehalfOfIdentifier[512];
int type;
bool notifyOnEntry;
bool notifyOnExit;
bool conservativeEntry;
union {
struct {
BOOL proximityUUID[512];
unsigned short major;
unsigned short minor;
int deFinitionMask;
bool notifyEntryStateOndisplay;
} beaconAttributes;
struct {
struct {
double latitude;
double longitude;
} center;
double radius;
double desiredAccuracy;
int referenceFrame;
} circularAttributes;
} ;
};
@interface CLBeaconRegion (Hidden)
- (id)initWithIdentifier:(Nsstring *)identifier;
- (struct ClientRegion)clientRegion;
@end
@implementation AIBBeaconRegionAny
- (id)initWithIdentifier:(Nsstring *)identifier;
{
return (self = [super initWithIdentifier:identifier]);
}
- (struct ClientRegion)clientRegion
{
struct ClientRegion clientRegion = [super clientRegion];
// deFinitionMask:
// 1 => uuid
// 3 => uuid + major
// 7 => uuid + major + minor
clientRegion.beaconAttributes.deFinitionMask = ~0x07;
return clientRegion;
}
@end
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)