//开启多线程一直扫描 当前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];
});
}
});
iOS 多线程下的NStimer 的使用
原创mb646b2b3c1359c 博主文章分类:iOS ©著作权
©著作权归作者所有:来自51CTO博客作者mb646b2b3c1359c的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java多线程的解析
Java多线程的解析 并发 并行 锁 CAS
守护线程 线程组 多线程 锁 -
NSTimer的使用
开启定时器 关闭定时器
时间处理 主线程 IT -
Python中list类型转换函数
Python坑又来了今天码哥为大家整理了平常被提问频率较高的一些问题1.我该下载哪个 Python 版本?去官网 http://python.org如果官网上的最新版本按钮没有替你自动下载,可从列表中选择 executable installer。如果你确信自己的系统是 64 位的,可以选 x86-64,否则选 x86 也没有问题。 我刚发现现在官网已经不再默认放置 2.
Python中list类型转换函数 python list转str python 提示文字2秒后清空 Python 官网