//开启多线程一直扫描 当前wifi是否和扫描到的wifi相同
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(isGoWebView:) userInfo:nil repeats:YES];
// do {
// [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
// } while (isCurrentWifiNameEqualToScanWifiName == NO); //当前wifi与扫码扫到的wifi不相同时
while (isCurrentWifiNameEqualToScanWifiName == NO) {
// [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
// [runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]]; //每隔10秒检查下线程循环条件
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];
}
if (isCurrentWifiNameEqualToScanWifiName == YES) {
dispatch_async(dispatch_get_main_queue(), ^{
WebViewController *wVC = [[WebViewController alloc] init];
[self.navigationController pushViewController:wVC animated:YES];
[wVC loadDataWithUrlStr:_regularString];
});
}
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(isGoWebView:) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
while (isCurrentWifiNameEqualToScanWifiName == NO) {
[runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];
}
if (isCurrentWifiNameEqualToScanWifiName == YES) {
dispatch_async(dispatch_get_main_queue(), ^{
WebViewController *wVC = [[WebViewController alloc] init];
[self.navigationController pushViewController:wVC animated:YES];
[wVC loadDataWithUrlStr:_regularString];
});
}
});
本文介绍了一种使用多线程技术周期性地检查当前Wi-Fi名称与目标Wi-Fi名称是否一致的方法,并在两者匹配时启动Web视图控制器加载指定URL。
2684

被折叠的 条评论
为什么被折叠?



