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 ...
随机推荐
- ClickHouse基本操作(二)
一.先来说一下,ClickHouse为啥快 MySQL单条SQL是单线程的,只能跑满一个core,ClickHouse相反,有多少CPU,吃多少资源,所以飞快: ClickHouse不支持事务,不存在 ...
- 实现es6中的set和map
转载自: https://www.cnblogs.com/hui-fly/p/9459152.html https://blog.csdn.net/roamingcode/article/detail ...
- excel导入DataTable
http://www.cnblogs.com/top5/archive/2010/03/12/1684559.html --下载excel的dll http://bbs.csdn.net/topics ...
- springboot中yml常用配置
server: port: 8080 spring: datasource: #数据源配置 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc: ...
- linux静态网络设置
一:NET模式 第一种: 第二种方式: 三:重启服务
- akka-typed(0) - typed-actor, typed messages
akka 2.6.x正式发布以来已经有好一段时间了.核心变化是typed-actor的正式启用,当然persistence,cluster等模块也有较大变化.一开始从名称估摸就是把传统any类型的消息 ...
- Spark SQL源码解析(五)SparkPlan准备和执行阶段
Spark SQL原理解析前言: Spark SQL源码剖析(一)SQL解析框架Catalyst流程概述 Spark SQL源码解析(二)Antlr4解析Sql并生成树 Spark SQL源码解析(三 ...
- 【JAVA习题七】输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
package erase; import java.util.Scanner; public class 字符串分类 { public static void main(String[] args) ...
- [JavaWeb基础] 031.dom4j写入xml的方法
上一篇我们讲述了dom4j读取xml的4种方法,甚是精彩,那么怎么样写入xml呢?我们直接看下源码实现. public static void main(String[] args) throws E ...
- Spring_基于配置文件的方式配置AOP
applicationContext-xml.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...