iOS-pthread && NSThread && iOS9网络适配
NSString
*str =
@"我是一个华丽的子线程";
pthread_create(&myPthread,
NULL,
longTimeOperation, (__bridgevoid*)(str));
#import "ViewController.h"
#import <pthread.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
pthread_t myPthread;
NSString *str = @"我是一个华丽的子线程";
pthread_create(&myPthread, NULL, longTimeOperation, (__bridge void*)(str));
}
void *longTimeOperation(void * data){
for (int i = 0; i < 10000; i++) {
NSLog(@"%s : %d %@ %@",__func__,i,[NSThread currentThread],data);
}
return NULL;
}
- (instancetype)initWithTarget:(id)target
selector:(SEL)selector object:(nullableid)argument
Source code:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSThread *mythread = [[NSThread alloc] initWithTarget:self selector:@selector(longTimeOperation:) object:@"我是华丽的子进程"];
mythread.name = @"longTime";
[mythread start];
}
- (void)longTimeOperation:(NSString *)parameter {
for (int i = 0; i < 10000; i++) {
NSLog(@"%s : %d %@ %@",__func__,i,[NSThread currentThread],parameter);
if (i == 9999) {
NSLog(@"退出进程");
[NSThread exit];
}
}
}
toTarget:(id)target withObject:(nullableid)argument;
withObject:(nullableid)arg
//
不常用:栈区大小/优先级
1>获得当前线程
+ (void)sleepUntilDate:(NSDate *)date;
- (void)setName:(NSString *)n;
NSLock
*lock = [[NSLockalloc]init];
加锁
解锁
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[NSThread detachNewThreadSelector:@selector(downLoadImage) toTarget:self withObject:nil];
//NSLog(@"%s : %@",__func__,[NSThread currentThread]);
}
- (void)downLoadImage {
NSLog(@"%s : %@",__func__,[NSThread currentThread]);
NSString *urlStr = @"http://img5.duitang.com/uploads/item/201408/18/20140818224957_2tkUd.jpeg";
// urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLQueryAllowedCharacterSet]];
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
[self performSelectorOnMainThread:@selector(downLoadImageView:) withObject:image waitUntilDone:YES];
//NSLog(@"------");
}
- (void)downLoadImageView:(UIImage *)image {
//NSLog(@"%s : %@",__func__,[NSThread currentThread]);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
imageView.image = image;
[self.view addSubview:imageView];
}
@end
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet
URLQueryAllowedCharacterSet]];
iOS-pthread && NSThread && iOS9网络适配的更多相关文章
- iOS9网络适配(ATS)
[转]iOS9 new_001:iOS9网络适配(ATS) 下载Xcode7打开APP后大家都发现自己的APP无法联网了,why? 苹果官方文档介绍如下: App Transport Security ...
- iOS9网络适配
今天升级Xcode7.0,发现网络访问失败. 输出错误信息:The resource could not be loaded because the App Transport Security po ...
- iOS多线程 NSThread/GCD/NSOperationQueue
无论是GCD,NSOperationQueue或是NSThread, 都没有线程安全 在需要同步的时候需要使用NSLock或者它的子类进行加锁同步 "] UTF8String], DISPA ...
- IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)
继续说说ios不同版本之间的适配 先说一个东西:在xcode当中有一个东西叫targets,苹果的官方文档是这样说的: A target specifies a product to build an ...
- IOS开发之不同版本适配问题2(#ifdef __IPHONE_7_0)(转载)
继续说说ios不同版本之间的适配 先说一个东西:在xcode当中有一个东西叫targets,苹果的官方文档是这样说的: A target specifies a product to build an ...
- iOS开发小技巧 - runtime适配字体
iOS开发小技巧 - runtime适配字体 版权声明:本文为博主原创文章,未经博主允许不得转载,有问题可联系博主Email: liuyongjiesail@icloud.com 一个iOS开发项目无 ...
- 李洪强iOS下的实际网络连接状态检测
iOS下的实际网络连接状态检测 序言 网络连接状态检测对于我们的iOS app开发来说是一个非常通用的需求.为了更好的用户体验,我们会在无网络时展现本地或者缓存的内容,并对用户进行合适的提示.对绝大部 ...
- 多线程之pthread, NSThread, NSOperation, GCD
关于多线程会有一系列如下:多线程之概念解析 多线程之pthread, NSThread, NSOperation, GCD 多线程之NSThread 多线程之NSOperation 多线程之GCD p ...
- ios9网络请求https适配
发现问题:今天升级Xcode 7.0 bata发现网络访问失败.输出错误信息: The resource could not be loaded because the App Transport S ...
随机推荐
- 百度智能云平台调用食物识别api Java实现
纪录一下我小学期2天花了20小时写的菜品识别java程序. 1.2. 百度智能云简介 1.2.1 百度图像识别服务 百度图像识别服务,基于深度学习及大规模图像训练,准确识别图片中的物体类别.位置.置信 ...
- P2444 [POI2000]病毒 AC自动机
P2444 [POI2000]病毒 #include <bits/stdc++.h> using namespace std; ; struct Aho_Corasock_Automato ...
- 谈谈C#中各种线程的使用及注意项~
说到线程,很多人会想到timer吧, 接下来我们就来学习一下 timer 吧,摇摇脑袋,清醒一下,接下来开始学习.... 一.基本概念 1.什么是进程? 当一个程序开始运行时,它就是一个 ...
- Java内存虚拟机理解
对于Java程序员,在虚拟机自动内存管理机制的帮助下,不需要再为每一个操作写配对的释放资源操作,不容易出现内存泄露和内存溢出问题.加深对Java虚拟机的理解,有助于在发现问题时精准定位问题,排 ...
- JavaScript实现单向链表结构
参考资料 一.什么是链表结构? 1.1.简介 链表和数组一样, 可以用于存储一系列的元素, 但是链表和数组的实现机制完全不同,链表中的元素在内存不是连续的空间,链表的每个元素由一个存储元素本身(数据) ...
- {dede:channelartlist} 改变偶数的class
{dede:channelartlist} <div {dede:global.itemindex runphp='yes'} if((@me %2) == 0){ @me = 'class=& ...
- SPL数据结构
数据结构是计算机存储.组织数据的方式. SPL提供了双向链表.堆栈.队列.堆.降序堆.升序堆.优先级队列.定长数组.对象容器. 基本概念Bottom:节点,第一个节点称Bottom:Top:最后添加的 ...
- vi和软件安装
一 vi编辑器简介 vim 全屏幕纯文本编辑器 二 vim使用 1 vi 模式 vi 文件名 命令模式 输入模式 末行模式 命令---->输入 a:追加 i:插入 o:打开 ...
- mybatis是怎样炼成的
前言 一些个人感受:不管分析什么源码,如果我们能摸索出作者的心路历程,跟着他的脚步一步一步往前走,这样才能接近事实的真相,也能更平滑更有趣的学习到知识.跟福尔摩斯探案一样,作者都经历了些什么,为什么他 ...
- [微信营销企划之路]003.Access forbidden!
引言 继<[微信营销企划之路]001.环境搭建(XAMPP+WeiPHP)>后,有不少朋友反应按照001教程配置虚拟多站点(<VirtualHost/>)后,部分站点会出现Ac ...