gpt4 book ai didi

ios - 在后台模式下循环

转载 作者:行者123 更新时间:2023-12-01 20:21:08 25 4
gpt4 key购买 nike

我想在后台搜索RSSI。我试图通过在同一函数中调用该函数来实现。无论如何,是否有使此循环处于后台模式的功能。如我所见,它应该生活在背景中,但是我死于索姆毫秒。如何使其不断搜索?

- (void)applicationWillResignActive:(UIApplication *)application
{
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
NSLog(@"Multitasking Supported");
}
else
{
NSLog(@"Multitasking Not Supported");
}

NSLog(@"Start background task");
mBeaconDeviceList = [[NSMutableArray alloc] init];
mBeaconConfigManager = [[JLEBeaconConfigManager alloc] init];
mBeaconConfigManager.delegate = self;
[mBeaconConfigManager startJaaleeBeaconsDiscovery];
}

#pragma mark - JLEBeaconConfigManager delegate
-(void)beaconConfigManager:(JLEBeaconConfigManager *)manager didDiscoverBeacon:(JLEBeaconDevice *)beacon RSSI:(NSNumber *)RSSI AdvData:(NSDictionary *)AdvData
{
NSLog(@"Find RSSI");
if ([RSSI intValue] > 0 || [RSSI intValue] < -40) {
return;
}

if ([mBeaconDeviceList containsObject:beacon]) {
[mBeaconDeviceList removeObject:beacon];
}
[mBeaconDeviceList addObject:beacon];
NSLog(@"FOUND: %@", RSSI);

NSLog(@"Start again");
mBeaconDeviceList = [[NSMutableArray alloc] init];
mBeaconConfigManager.delegate = self;
[mBeaconConfigManager startJaaleeBeaconsDiscovery];
}

最佳答案

您可以将背景时间延长到3分钟,这将使您有更多时间从RSSI中进行搜索。您可以像这样在applicationDidEnterBackground中扩展它:

- (void)extendBackgroundRunningTime {
if (_backgroundTask != UIBackgroundTaskInvalid) {
// if we are in here, that means the background task is already running.
// don't restart it.
return;
}
NSLog(@"Attempting to extend background running time");

__block Boolean self_terminate = YES;

_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"DummyTask" expirationHandler:^{
NSLog(@"Background task expired by iOS");
if (self_terminate) {
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
_backgroundTask = UIBackgroundTaskInvalid;
}
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Background task started");

while (true) {
NSLog(@"background time remaining: %8.2f", [UIApplication sharedApplication].backgroundTimeRemaining);
[NSThread sleepForTimeInterval:1];
}

});
}

关于ios - 在后台模式下循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35706497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com