背景:项目要实现unity3d调用ibeacon小范围内定位的功能,无奈直接集成在unity里的ibeacon发布ios版之后,只要ibeacon设备灯不亮就获取不到范围,多次调试未果,最终决定从ios端集成,再通过unity调用,亲测成功,简单记录一下。直接贴代码
/***********************oc端代码**********************/
// ibeacon.mm
// ibeacon
//
// Created by 他三叔,走啊 on 16/8/23.
// Copyright © 2016年 他三叔,走啊. All rights reserved.
//
#import "ibeacon.h"
#import <CoreLocation/CoreLocation.h>
#import<CoreBluetooth/CoreBluetooth.h>
#import "Reachability.h"
#define MY_REGION_IDENTIFIER @"my region"
#define MY_UUID @"5E96BDB3-89B0-4999-85CB-E622CA8A84A8"
@interface ibeacon : NSObject<CLLocationManagerDelegate,CBPeripheralManagerDelegate>
{
CLLocationManager *_locationManager;
CLBeaconRegion *_region;
NSString *bluetooth;
NSString *isNetWork;
NSString *device;
}
@property (nonatomic,strong) CBPeripheralManager *manager;
- (void) turnOnBeacon:(NSString *)uuid;
@end
ibeacon *beacon = NULL;
#if defined(__cplusplus)
extern "C"{
#endif
void pushUUID()
{
if(beacon == NULL)
{
beacon = [[ibeacon alloc]init];