This is on iOS... Say I have use a method that has some kind of
result/completion block like ALAssetsLibrary assetForURL In the
example below, in the assetForURL result block, the JPEG
representation of the asset is read into a buffer and the NSData form
of that buffer is assigned to a property. I need the property to be
set before my code continues past his point. How do I go about
accomplishing that? Am I forced to show a "waiting for xxx" view until
this finishes?

I tried surrounding the assetForURL call with a semaphore but this
does not work on the main app thread (the dispatch_semaphore_wait()
blocks the main thread and thus the dispatch_semaphore_signal() in the
resultBlock never gets to run to signal that the block is done).

I guess in general I an wondering how I correctly wait for things to
happen that I absolutely positively need to be done before I
continue...

Thanks in advance...

Chris

* * *

-(void)getJPEGFromAssetForURL:(NSURL *)url {
        ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
        [assetslibrary assetForURL:url
            resultBlock: ^(ALAsset *myasset) {
                ALAssetRepresentation *rep = [myasset defaultRepresentation];
                Byte *buf = malloc([rep size]);
                NSError *err = nil;
                NSUInteger bytes = [rep getBytes:buf fromOffset:0LL
length:[rep size] error:&err];
                if (err || bytes == 0) {
                    [...]
                }
                self.imageJPEG = [NSData dataWithBytesNoCopy:buf
length:[rep size] freeWhenDone:YES];
            }
            failureBlock: ^(NSError *err) {
                NSLog(@"can't get asset %@: %@", url, err);
            }];
        [assetslibrary release];
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to