Tag: asynchronous

parsing消息应用程序,需要find一种方法来延迟代码执行,直到deleteAllInBackground完成执行。 包括详细的代码

与我的代码有一些问题,我正在使用Parse框架构build一个简单的消息传递系统。 我需要以某种方式延迟方法的调用,直到后台进程完成执行。 代码如下。 首先,我将UIViewController注册为Parse Push Notification的观察者。 当收到一个推送被调用的方法receivedPush 。 收到推送然后调用displayMessages 。 – (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedMessage) name:@"receivedPush" object:nil]; } -(void)receivedMessage { [self displayMessages]; } -(void)displayMessages { //here I want to cycle through the message objects NSMutableArray *toDelete = [[NSMutableArray alloc] init]; PFQuery *messageBankQuery = [PFQuery queryWithClassName:@"messageBank"]; [messageBankQuery whereKey:@"username" equalTo:[PFUser currentUser].username]; [messageBankQuery findObjectsInBackgroundWithBlock:^(NSArray […]

崩溃在iPhone开发下载asynchronous图像

我正在使用这个链接下载asynchronous图像,并将它们显示在我的表视图上,同时我使用相同的asynchronous类到我的下一个视图,但是当上次调用deallocasynchronous类,然后我的应用程序崩溃。 有人请帮助我,在此先感谢。

Swift,从asynchronous块返回值

对于iOS开发来说,这是一个很新的东西,我刚刚开始涉足GCD,我已经阅读了几篇关于SO的文章,并且已经咨询了Apple的文档,但是我很难理解如何从“昂贵”的操作中设置返回值。 下面的函数将遍历总和100K用户(作为一个例子),在主线程上这样做显然会停止GUI几秒钟,因此在我的UserList类中,我build议在我的线程上asynchronous执行这个块: let queue = dispatch_queue_create("me.alexsims.user_queue", DISPATCH_QUEUE_CONCURRENT) public func getUserById(userId: String, completionHandler: (result: User) -> ()) { dispatch_async(queue) { for user in self.users { if user.getUserId() == userId { completionHandler(result: user) } } // Return an empty user object completionHandler(result: User()) } } 现在从我的理解, resultvariables应该返回,然后我应该能够访问从我的主线程存储在那里的User()对象 但是,当我返回到我的控制器并运行testing时: var list = UserList() var a_user = User() a_user […]

NSOperationQueue内部的NSOperation中的asynchronouscallback从来没有被调用过

我需要链接几个NSOperation s在一个NSOperationQueue做networking调用,然后等待所有完成。 我将所有的NSOperation添加到我的NSOperationQueue ,然后调用operationQueue.waitUntilAllOperationsAreFinished() 。 这是有效的,但是它会无限期地等待,因为NSOperations的callback将操作的状态设置为“已完成”,因此永远不会被调用。 我正在使用以下NSOperation子类: class ConcurrentOperation: NSOperation { enum State: String { case Ready, Executing, Finished private var keyPath: String { return "is" + self.rawValue } } var state: State = State.Ready { willSet (newValue) { self.willChangeValueForKey(newValue.keyPath) self.willChangeValueForKey(self.state.keyPath) } didSet { self.didChangeValueForKey(oldValue.keyPath) self.didChangeValueForKey(self.state.keyPath) } } } extension ConcurrentOperation { override var ready: […]

asynchronous获取Swift Xcode

我使用集合视图来显示存储在CoreData中的图像,只有less数几个(大约15),但是当我向下滚动它时,它的接缝是因为我不是asynchronous获取我的数据,是只有15 UIImages可能吗? 所以这里是我的问题,我无法find任何地方的asynchronous获取下降教程,3天我期待。 对不起,如果我没有好好search。 这是从教程中得到的一些东西 let entity = NSEntityDescription.entityForName("Dreams", inManagedObjectContext: contxt) let fetchRequest = NSFetchRequest() fetchRequest.entity = entity let asyncFetch = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) { (result:NSAsynchronousFetchResult!) -> Void in if result.finalResult!.count > 0 { self.dreams = result.finalResult! as [Dream] } NSLog("Done.") } 梦是一个types的数组[梦想],但是当我显示集合视图什么都没有出现这是我以前做过的 let fetchRequest = NSFetchRequest(entityName: "Dreams") if let fetchResults = contxt.executeFetchRequest(fetchRequest, error: nil) as? […]

从摄像头获取所有图像asynchronous

我想从摄像头asynchronous获取所有图像现在我正在使用该代码,但我的应用程序被绞死,直到所有的图像检索,我注意到在instigram或其他应用程序,它不需要时间来从camerroll加载图片。 -(void)getAllPictures { NSLog(@"im in "); imageArray=[[NSArray alloc] init]; mutableArray =[[NSMutableArray alloc]init]; NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init]; library = [[ALAssetsLibrary alloc] init]; void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { NSLog(@"im in block"); if(result != nil) { if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { NSLog(@"result not nill"); [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]]; […]

如何asynchronous加载dynamicUITableView图像?

现在我有一个图像和标签的自定义单元格。 后来我打印这些细胞: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell:customCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! customCell var url = NSURL(string: postCover[indexPath.row]) if let data = NSData(contentsOfURL: url!) { cell.cellImage.image = UIImage(data: data) } var title = postTitle[indexPath.row] cell.cellLabel.text = title let indexPath = tableView.indexPathForSelectedRow() return cell } 当我打开一个应用程序,并滚动它冻结。 我该如何解决这个错误? 我读了一下,我必须在我的tableView中使用asynchronous图像加载,但我不加载它们asynchronous已经? 我search了4-5天,一无所有。 任何人都可以给我一些提示,请吗?

如何正确使用完成处理程序

我明白完成处理程序是如何工作的,但是在语法上有点混乱。 下面是一个函数,给定一个用户名,调用一个分析查询找出相应的userId。 查询结束后函数返回(所以它返回nil),这就是为什么我们需要完成处理程序。 我如何实现它? func getUserIdFromUsername(username: String) -> String { var returnValue = String() let query = PFQuery(className: "_User") query.whereKey("username", equalTo: username) query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in if let objects = objects { for object in objects { returnValue = object.objectId! } } } return returnValue } 注:我知道类似的例子存在,但他们要么不快,要么非常冗长。 这是一个简短的,包含Parse的版本。

NSURLConnectionasynchronous不起作用

我试图做一个asynchronousNSURL请求,但我得到所有“假”。 -(BOOL)checkConnectionForHost:(NSString*)host{ BOOL __block isOnline = NO; NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:host] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:1]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if([(NSHTTPURLResponse*)response statusCode]==200){ isOnline = TRUE; } }]; NSLog(@"%i",isOnline); return isOnline; } 此外,这个代码被称为“6”次,当我实际上只是用它: -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 并且在我的数据源中只有3个单元格或3个项目。 第一次在Objective-C中处理asynchronous和callback,所以一个详细的答案将不胜感激! 谢谢!

如果方法使用NSURLConnection如何返回输出与块的asynchronous调用

我正在向服务器发送请求以使用NSURLConnection块方法获得响应。 我不能使用返回YES或在块中返回NO。 我怎样才能解决这个问题? -(BOOL)checkForValidUrl:(NSString *)url { __block int httpStatus=0; NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]]; [request setValue:@"application/json" forHTTPHeaderField:@"content-type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error) { httpStatus = [((NSHTTPURLResponse *)response) statusCode]; NSLog(@"httpStatus inside block:%d",httpStatus); } ]; return NO; }