iOS 多线程下的NStimer 的使用
2015-12-02 17:02
579 查看
//开启多线程一直扫描
当前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];
});
}
});
当前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开发常见正则表达式
- ios textField 输入值监听
- iOS RunLoop 初识
- iOS开发笔记-判断输入的是否是字母
- iOS开发之核心动画
- iOS开发笔记- 判断是否是数字
- [原]iOS--字符编码,NSString和UTF-8间的转换
- 好的iOS GitHub链接
- iOS客户端学习-SDWebImage
- iOS-自定义AlertView(便利构造器)
- iOS 开发笔记和技巧总结(一)
- Dynamic linking static library on iOS
- iOS 容器视图控制器
- px像素单位与IOS像素单位的换算
- iOS --- block的一些使用方法(反向传值)
- iOS某操作霸占主线程过久导致界面假死的一种解决方法
- ios 基本图形的绘制
- iOS通知的添加和移除
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- iOS基础知识点