Advertisement
Guest User

NSOperation

a guest
Jul 20th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <Foundation/Foundation.h>
  2.  
  3. @interface DisplayImages : NSOperation {   
  4.    
  5.     NSURL *imageUrl;   
  6.     UIImageView *imageView;
  7. }
  8.  
  9. @property (nonatomic,retain) NSURL *imageUrl;
  10. @property (nonatomic,retain) UIImageView *imageView;
  11.  
  12. -(id)initWithAttributes:(NSURL *)imageUrlFromMain ImageView:(UIImageView *)imageViewFromParent;
  13.  
  14. @end
  15.  
  16.  
  17.  
  18.  
  19. #import "DisplayImages.h"
  20. #import <AssetsLibrary/AssetsLibrary.h>
  21. #import "NSOperationalQueueViewController.h"
  22. @implementation DisplayImages
  23.  
  24. @synthesize imageUrl;
  25. @synthesize imageView;
  26.  
  27.  
  28. -(id)initWithAttributes:(NSURL *)imageUrlFromMain ImageView:(UIImageView *)imageViewFromParent{
  29.      
  30.     if (![super init]) return nil;
  31.    
  32.     [self setImageUrl:imageUrlFromMain];
  33.    
  34.     [self setImageView:imageViewFromParent];
  35.    
  36.      return self;
  37. }
  38.  
  39. -(void)main{   
  40.    
  41.     typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
  42.     typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);    
  43.    
  44.     ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
  45.    
  46.         ALAssetRepresentation *rep = [myasset defaultRepresentation];
  47.         CGImageRef iref = [rep fullResolutionImage];
  48.         UIImage *topicImage;   
  49.        
  50.         if (iref){
  51.            
  52.             topicImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
  53.            
  54.             self.imageView.image = topicImage;
  55.            
  56.             //NSOperationalQueueViewController *temp = (NSOperationalQueueViewController *)[NSOperationalQueueViewController getParent];
  57.            
  58.             //[temp performSelectorOnMainThread:@selector(displayImages:) withObject:self.imageView waitUntilDone:YES];    
  59.            
  60.         }  
  61.     };  
  62.    
  63.     ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror){
  64.    
  65.     };
  66.    
  67.     NSLog(@"Url is %@",(NSString *)imageUrl);
  68.    
  69.     ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
  70.     [assetslibrary assetForURL:imageUrl
  71.                    resultBlock:resultblock
  72.      
  73.                   failureBlock:failureblock];    
  74. }
  75.  
  76. -(void)dealloc{
  77.    
  78.     [imageUrl release];
  79.     imageUrl = nil;
  80.    
  81.     [imageView release];
  82.     imageView = nil;   
  83.    
  84.     [super dealloc];
  85. }
  86.  
  87. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement