实时从iBeacon切换到BLE? [英] Switching from iBeacon to BLE in real time?

查看:100
本文介绍了实时从iBeacon切换到BLE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的信标硬件被编程为iBeacon +可写BLE. 因此,我可以使用iBeacon发现它,也可以通过BLE连接到它.

Our beacon hardware was programmed to be iBeacon + writeable BLE . So i can discover it with iBeacon , and also connect to it via BLE.

我想扫描iBeacon,当我进入该区域(应用程序在后台)并且正在调用该代表时,他将切换到BLE并使用BLE连接到该设备:

I would like to scan for iBeacon, and when i enter the region (app is in background) , and the delegate is being called, he will than switch to BLE and connect to the device with BLE :

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    // here connect as usual via bluetooth
}

因此,正如我所说,我可以单独编写/发现硬件,但是当我尝试通过BLE从代理连接到模块时(当应用在后台运行时,我进入该区域,代理处于打开状态,然后在后台尝试与BLE连接时, 它不起作用,尽管我可以在后台在区域内执行其他操作,例如,连接到服务器.)

So,as i said, i can separately write/discover the hardware, but when i am trying to connect to the module, from the delegate via BLE ( when app in background,i enter the region,delegate is ON, than in background trying to connect with BLE, its not working, although i can in background do other things when inside a region, for example, connect to a server .)

我能做些什么来实现它吗?我还试图停止监视信标区域,但是即使这样,他也无法从后台连接到BLE.

Is there anything i can do to make it happen? i was also trying to stop the beacon region monitoring, but even so, he can't connect to the BLE from background .

推荐答案

要在bg中进行操作,您需要向操作系统请求时间.然后,您将获得一个标识符.

to do stuff in bg you need to request time from the os. you then get an identifier.

//identifier
@property(nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskIdentifier;

通过调用它来请求它:

if(!self.backgroundTaskIdentifier) {
    self.backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        NSLog(@"expired, fail, throw!!!");
        @throw [NSException exceptionWithName:@"BeaconServiceKilled" reason:@"Expired in bg" userInfo:nil];
    }];
}

完成后释放它

if(self.backgroundTaskIdentifier) {
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier];
    self.backgroundTaskIdentifier = 0;
}

这篇关于实时从iBeacon切换到BLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆