小编iDe*_*mit的帖子

如何在IOS中取消/退出/停止Thread对象或后台运行的线程的执行

我正在分离一个线程在后台执行一些操作,请参考下面的代码

 currentThread = [[NSThread   alloc]initWithTarget:contactServiceselector:@selector(requestForContactBackup:)object:msisdn];

 [currentThread start];
Run Code Online (Sandbox Code Playgroud)

这个currentThread就是AppDelegate中声明的指针。我的视图上有一个按钮,点击它,后台线程的执行应该停止。参考下面的代码:

-(void)cancelTheRunningTasks {
    
   if(self.currentThread !=nil) {

        [currentThread cancel];
        NSLog(@"IsCancelled: %d",[currentThread isCancelled]);   //here Yes returns
        [self removeNetworkIndicatorInView:backUpViewController.view];
    }  
}
Run Code Online (Sandbox Code Playgroud)

下面代码的问题是后台线程仍然处于执行状态。

我的问题是,有了线程引用,如何从主线程取消/停止执行/杀死后台线程?

请建议我可能的解决方案。谢谢。

iphone objective-c ios5 ios6

6
推荐指数
1
解决办法
2万
查看次数

在 C 语言的 libcurl 库中设置标头标志选项

我正在执行 Post 请求,为此我必须设置标头内容类型,因为application/json我正在编写以下代码:

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8");
res = curl_easy_setopt(curl, CURLOPT_HEADER,headers);
Run Code Online (Sandbox Code Playgroud)

但是当我编译程序时,错误出现为

Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 22
Content-Type: application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)

application/json请帮我尽快设置此内容类型

c libcurl

4
推荐指数
1
解决办法
5061
查看次数

标签 统计

c ×1

ios5 ×1

ios6 ×1

iphone ×1

libcurl ×1

objective-c ×1