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 ...
随机推荐
- 6、保持会话(save)
前言 为什么要保存会话呢?举个很简单的场景,你在上海测试某个功能接口的时候,发现了一个BUG,而开发这个接口的开发人员是北京的一家合作公司.你这时候给对方开发提bug, 如何显得专业一点,能让对方心服 ...
- XShell 评估到期
刚刚打开XShell弹出”评估到期“,点击确定后自动打开中文官网,得购买后才能使用. 当初下载的时候没留意到会有这一天.. 手头拮据的朋友可以通过下面方法绕过: 删除XShell. 到英文官网下载页找 ...
- nginx+vue+uwsgi+django的前后端分离项目部署
Vue+Django前后端分离项目部署,nginx默认端口80,数据提交监听端口9000,反向代理(uwsgi配置)端口9999 1.下载项目文件(统一在/opt/luffyproject目录) (1 ...
- EF Join连接查询的坑
最近做项目的时候遇到一个需要级联查询的数据,表中又没有定义相关的外键约束,所以限定了咱们只能使用Join方式的关联而不是Include的方式关联,关于Include和Join的详细用法,本屌就不再此处 ...
- wannafly挑战赛4树的距离 离线处理,dfs序
时间限制:C/C++ 2秒,其他语言4秒空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 wyf非常喜欢树.一棵有根数树上有N个节点, ...
- 【Redis】linux中 使用yum下载并安装redis
1.检查是否有redis yum 源 yum install redis 2.下载fedora的epel仓库 yum install epel-release 3.安装redis数据库 yum ins ...
- 新版Element-UI级联选择器高度位置不对的问题
在做电商后台管理系统项目事遇到的问题,可能视频是去年的,element现在已经是新版本了,有些地方修改了,从而导致了以下问题 级联选择器的位置不对 解决的方法就是在全局css中添加以下代码: .el- ...
- IIS 报 :HTTP Error 503. The service is unavailable.
打开IIS 找到你对应的网站名称然后你会发现应用池停止了 点击你对应的网站右键点击启动既可
- 《HelloGitHub》第 50 期
兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. 这是一个面向编程新手.热爱编程.对开源社区感兴趣 人群的月刊,月刊的内容包括:各种编 ...
- [JavaWeb基础] 023.线程安全(二)
上一篇我们讲解了线程安全的问题,那么要解决线程安全的问题,我们就必须用到线程同步,保证线程之间不互相影响而产生脏数据,下面我们来讲讲具体的实现吧. 首先我们看下例子,我们有个Outputter类,用于 ...