tiechui

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1- asihttprequest code

~~CFHTTPMessageCreateRequest

NSURLConnection(NSNetwork) 会自动调用操作系统设置的代理,

CFHTTPMessageCreateRequest(CFNetwork) 则不会

CF的这套框架是很底层的, 很多东西都要自己弄,CFNetworkCopySystemProxySettings()需要手动调用,

例子

可以, 我刚写完这部分 你需要在发送请求后,读取返回信息, 最后才是status 大概是这样的 CFHTTPMessageRef request = CFHTTPMessageCreateRequest() CFHTTPMessageSetBody(request, data) ./.... CFHTTPMessageSetHeaderFieldValue(request, CFSTR("field"), CFSTR("value")); _stream = CFReadStreamCreateForHTTPRequest(allocator, request ); if( !CFReadStreamOpen(_stream) ) { // error handler } CFindex numBytesRead; do{ UInt8 buf[1024]; numBytesRead = CFReadStream( _stream, buf, sizeof(buf) ); if( numBytesRead .>0 ) {   // save data,  contents from server } else break; } 之后才可以获得 status 这是阻塞模式, 如果想用异步模式则需要写回调函数, 根据需要选择

 

~~CFHTTPMessageApplyCredentialDictionary

CFHTTPMessageSetHeaderFieldValue

CFReadStreamCreateForHTTPRequest

CFReadStreamSetProperty

CFStreamClientContext

CFReadStreamOpen

 

2-http://mmz06.blog.163.com/blog/static/12141696201221801854174/

http://blog.csdn.net/sirodeng/article/details/8236348

GHUnit  xcode单元测试框架

 

3-http://blog.csdn.net/cssmhyl/article/details/7920667

mac iOS socket 通信

 

4*****-http://blog.csdn.net/cssmhyl/article/details/7920657

iOS 多线程

一个进程(任务)必须有一个主线程,所有界面的显示操作即AppKitUIKit的操作必须在主线程进行

每个进程有独立的虚拟内存空间。其中的线程共享。

线程有自己的Stack空间和消耗一定的CPU时间

创建新线程就是给进程增加了一个执行流

1)NSThread

      a)NSThread-new - main

       b) detachNewThreadSelector:toTarget:withObject

2) NSObject

[myObj performSelectorInBackground:@selector(doSomething) withObject:nil];

 

3)POSIX Thread

#include <stdio.h>

#include <pthread.h>

#include <unistd.h>

 

void *pthreadRoutine(void *);

 

 

int main (int argc, const char * argv[])

{

    pthread_attr_t  attr;

    pthread_t       pthreadID;

    int             returnVal;

 

    returnVal = pthread_attr_init(&attr);

    returnVal = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    int threadError = pthread_create(&pthreadID, &attr, &pthreadRoutine, NULL);

    returnVal = pthread_attr_destroy(&attr);

 

    if (threadError != 0)

    {

        // Report an error.

    }

 

    sleep(10);

 

    return 0;

}

 

 

void *pthreadRoutine(void *data){

    int count = 0;

    while (1) {

        printf("count = %d\n",count++);

        sleep(1);

 

    }

    return NULL;

}

 

~~NSOperation&NSOperationQueue

- (void)setMaxConcurrentOperationCount:(NSInteger)count //控制并发数

 

 

~~GCDGrand Central Dispatch

一系列的BSD层面的接口,在Mac 10.6 iOS4.0以后才引入的,且现在NSOperationNSOperationQueue的多线程的实现就是基于GCD

GCD大都数接口的调用都依赖于Block

比如一个在UIImageView中显示一个比较大的图片

dispatch_queue_t imageDownloadQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);    

dispatch_async(imageDownloadQueue, ^{

        NSURL *imageURL = [NSURL URLWithString:@"http://test.com/test.png"];

       NSData *imageData = [NSData dataWithContentsOfURL:imageURL];

        UIImage *image = [UIImage imageWithData:imageData];

       dispatch_async(dispatch_get_main_queue(), ^{

            [imageView setImage:image];//UIKit必须在主线程执行

        });

    });

 

.线程间通信息

1.performSelect On The Thread

performSelectorOnMainThread

performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:

2.Mach Port

~~父线程 + 父MachPort

做参数传递给子线程==》子线程可以对父通信

~~子先向父发送特殊消息,传递子MachPort给父,父向子通信

~~MachPort 有delegate和schdule,到自己线程的RunLoop

.RunLoop---未完

RunLoop 线程中的循环,圈

 

5*****https://github.com/kejinlu/objc-doc/blob/master/Block.md

block学习

6****http://www.cnblogs.com/imlucky/archive/2011/10/18/2216829.html

AsyncSocket

posted on 2013-02-18 09:40  tiechui  阅读(288)  评论(0编辑  收藏  举报