i schedule a Timer to read RSSI using readRSSI function ,but the timer stops when my app go into background

StackOverflow https://stackoverflow.com/questions/15651940

سؤال

I schedule a Timer to read RSSI using readRSSI function ,but the timer stops when my app go into background. Maybe there is a good method to get RSSI value from peripheral's notification when app comes into background . But I don't know how to do. Could anybody help me? Anyone has a better method?

هل كانت مفيدة؟

المحلول

I have got the same problem, and I have two idea.

1.

First, you should have some service that got corebluetooth delegate periodly. F or my example, I have a battery service that I can got delegate with didUpdateValueForCharacteristic periodly.

Second, set readRSSI function in didUpdateValueForCharacteristic. And don't forget to set background mode with Corebluetooth.So now you can got the RSSI updating when update battery value.

This works fine for me, but I got another idea from some sample code.

2.

Use the code below whenever you want to start the RSSI reader:

NSTimer *rssiTimer; 
[rssiTimer invalidate];    
rssiTimer = [NSTimer timerWithTimeInterval:1.0 target:peripheral selector:@selector(readRSSI) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:rssiTimer forMode:NSRunLoopCommonModes];

It works fine for me too.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top