我有一个项目,使用后台下载图像NSOperationQueue.它一直在使用IOS 4.3的设备上工作.但是,如果我使用基本sdk 4.3或5构建应用程序并使用IOS5在设备上运行应用程序,则应用程序崩溃.启动应用程序时,它会将NSOperation对象添加到队列中以下载图像.如果在我之间按下后退按钮,我取消它NSOperation并且它崩溃并在控制台上显示以下跟踪:
#0 0x004727b7 in ____NSOQSchedule_block_invoke_0 () #1 0x026a5618 in _dispatch_call_block_and_release () #2 0x026a7a10 in _dispatch_worker_thread2 () #3 0x974bb781 in _pthread_wqthread () #4 0x974bb5c6 in start_wqthread ()
并打印"ResourceLoadOperation isFinished = YES,而不是由它所在的队列启动"如果我评论取消方法调用,应用程序不会崩溃.NSOperationIOS5 的更改是否有任何更新?
我需要做一系列的url调用(获取WMS tile).我想使用LIFO堆栈,因此最新的url调用是最重要的.我想现在在屏幕上显示瓷砖,而不是5秒前在屏幕上显示在屏幕上的瓷砖.
我可以从NSMutableArray创建自己的堆栈,但我想知道NSOperationQueue是否可以用作LIFO堆栈?
我正面临着我的应用程序的设计问题.
基本上,以下是我在我的应用程序中要做的事情.
单个任务是这样的:
可能会同时执行许多任务.
一个任务中的步骤显然是ordered(即,没有第2步下载json,第3步不能继续),但它们也可以discrete.我的意思是,例如,task2的第4步可以在task1的第3步之前执行(如果task2的下载速度比task1的更快)
任务有优先事项.用户可以启动具有更高优先级的任务,因此将尝试在所有其他任务之前执行所有任务的步骤.
我希望UI能够尽可能地响应.
所以我打算创建一个优先级最低的NSThread.
我在该线程中放置了一个自定义优先级事件队列.任务的每一步都成为一个事件(工作单位).因此,例如,下载json的步骤1成为事件.下载后,该事件会为步骤3生成另一个事件并将其放入队列中.每个事件都有自己的优先级设置.
现在我看到这篇文章:并发和应用程序设计.Apple建议我们Move Away from Threads使用GCD或NSOperation.
我发现这NSOperation与我的草稿设计相匹配.但我有以下问题:
谢谢
请告诉我如何在C++中实现NSOperation和NSOperationQueue功能.
我创建了一个NSOperationQueue下载图像(从Twitter获取Cell):
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[queue addOperationWithBlock:^{
NSString *ImagesUrl = [[NSString alloc]initWithFormat:@"http://api.twitter.com/1/users/profile_image/%@",[[status objectForKey:@"user"]objectForKey:@"screen_name"]];;
NSURL *imageurl = [NSURL URLWithString:ImagesUrl];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageurl]];
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
if (img.size.width == 0 || [ImagesUrl isEqualToString:@"<null>"]) {
[statusCell.imageCellTL setFrame:CGRectZero];
statusCell.imageCellTL.image = [UIImage imageNamed:@"Placeholder"] ;
}else
[statusCell.imageCellTL setImage:img];
Run Code Online (Sandbox Code Playgroud)
这工作正常,但当它似乎移动滚动和查看图像仍在加载,并且他们正在改变几次,直到你得到一张图片.
而且我不喜欢诊断时间的轮廓,所以我想以某种方式NSOperationQueue在背景中做到这一点
还可以展示如何使"Imagecache"无需下载已下载的图像.
**(状态= Twitter时间轴的NSDictionary).
编辑::(所有单元格)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Celulatime";
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ( [Cell isKindOfClass:[TimeLineCell class]] ) {
TimeLineCell …Run Code Online (Sandbox Code Playgroud) cocoa-touch asynchronous nsoperationqueue grand-central-dispatch ios
我面临与NSoperationQueue相关的问题.在我的代码中:
-(void) viewDidLoad
{
//Initialisation of queue and operation.
//adding operation to queue
[self.operationQueue addOperation:op];
}
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.operationQueue cancelAllOperations];
}
Run Code Online (Sandbox Code Playgroud)
所以在执行我的NSOperation主函数时,当我检查isCancelled属性时,它总是返回NO.在NSOperationQueue上调用cancellAllOperation之后的事实.例如.
-(void)main
{
if(self.isCancelled)
{
// Never executing this block :-(
}
}
Run Code Online (Sandbox Code Playgroud)
欲了解更多详细信息,我在做我的NSOperation.And一些网络电话,当我切换到另一种观点届时cancelAllOperation的叫了起来.当网络响应回到我的NSOperation时,我正在检查是否(Self.isCancelled),现在我在另一个视图中(意味着isCancelled应该设置为YES).但这个检查总是失败.
有没有办法记录运行/调用方法的线程或队列?就像是:
- (void)foo
{
NSLog(@"Running on %@ queue, %@ thread", queue, thread);
}
Run Code Online (Sandbox Code Playgroud) multithreading objective-c nsoperationqueue grand-central-dispatch ios
我在crashlytics中得到了一些崩溃报告,我完全不明白,这里是崩溃线程的崩溃日志:

我没有找到任何关于我的代码的提示,也不是可重现的或仅在特定设备上发生的事情.根据Crashlytics的说法,它不是RAM或磁盘空间的问题,所以我在这里真的很无奈.
有没有人对堆栈跟踪有一些提示?
我的任务是逐个将多个图像上传到服务器.所以我正在使用批处理操作过程.每次我开始上传程序时,一些操作特别是第一个操作一旦启动就完成并且图像没有上传,然后批量上载过程继续正常,并且遗漏了其他图像的罕见故障.
我使用的代码如下: -
-(void)callWSToUploadRxs{
NSLog(@"the total assets maintained are %lu", (unsigned long)_arr_assetsMaintained.count);
NSMutableArray *mutableOperations = [NSMutableArray array];
int imageUploadCount = (int)[self extractFullSizeImagesToUpload].count;
// second for loop is to initialize the operations and then queue them.
for (int i = 0; i<imageUploadCount; i++) {
NSData *imageData = UIImageJPEGRepresentation([_arr_originalImagesToSend objectAtIndex:i],1.0);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"POST"];
NSLog(@"the url constructed is %@", [NSString stringWithFormat:@"%@/%@/%@/%@",uploadRxUrl,@"4004DD85-1421-4992-A811-8E2F3B2E49F7",@"5293",[_arr_imageNames objectAtIndex:i]]);
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@/%@.jpg",uploadRxUrl,@"4004DD85-1421-4992-A811-8E2F3B2E49F7",@"5293",[_arr_imageNames objectAtIndex:i]]]];
[request setValue:@"binary/octet-stream" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:imageData];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; …Run Code Online (Sandbox Code Playgroud) nsoperation nsoperationqueue grand-central-dispatch ios afnetworking
我正在开发一个自定义相机应用程序.我正在做的是,我正在使用相机拍照并在屏幕的同一个VC底部显示它们.
我将图像存储在本地词典和NSDocument目录路径中.如果图片在本地词典中,它将从本地字典中获取,它将从NSDocument目录路径获取.
收到内存警告后,我只是字典,所以它将从NSDocument目录路径获取图像.
使用两者将在缓慢的过程中显示图像.我的UI在显示图像方面没有那么好.
所以我想使用NSOperation将图像存储在NSDocument目录路径中.
我对NSOperation知之甚少.我在谷歌搜索,我只是得到快速的教程,而我需要帮助Objective C.
所以,请任何人都可以解释NSOperation和NSOperationQueue举例?
nsoperationqueue ×10
objective-c ×6
ios ×5
nsoperation ×5
afnetworking ×1
asynchronous ×1
c++ ×1
cocoa-touch ×1
crashlytics ×1
dealloc ×1
iphone ×1
nsthread ×1