2

I'm trying to apply Unsynchronized's answer (Drawing waveform with AVAssetReader) while using ARC. There were only a few modifications required, mostly release statements. Many thanks for a great answer! I'm using Xcode 4.2 targeting iOS5 device.

But I'm getting stuck on one statement at the end while trying to invoke the whole thing.

Method shown here:

-(void) importMediaItem {

    MPMediaItem* item = [self mediaItem];

    waveFormImage = [[UIImage alloc ] initWithMPMediaItem:item completionBlock:^(UIImage* delayedImagePreparation){

        [self displayWaveFormImage];
    }];

    if (waveFormImage) {
       [self displayWaveFormImage];
    }
}

On the call to initWithMPMediaItem I get the following error:

Automatic Reference Counting Issue.  Receiver type 'UIImage' for instance message 
does not declare a method with selector 'initWithMPMediaItem:completionBlock:'

Since I do have the method initWithMPMediaItem declared in the class header, I really don't understand why I'm getting this error.

- (id) initWithMPMediaItem:(MPMediaItem*)item
       completionBlock:(void (^)(UIImage* delayedImagePreparation))completionBlock;

Been trying to wrap my head around this for several hours now but to no avail. Is my method declaration wrong for this type of method? Thanks!

Community
  • 1
  • 1
JimVision
  • 454
  • 4
  • 15
  • The main issue is that you are calling initWithMPMediaItem on a UIImage. It is declared as a method in your class (I think, can't really know until you show us the header it is declared in) so it is expecting to be called on self (which I assume is not a UIImage). You need to decide how you want this this method to act - should it be in a UIImage category? – sosborn Mar 01 '12 at 01:25

1 Answers1

2

It looks like initWithMPMediaItem should be declared as an initializer for UIImage. So you should declare it inside a UIImage category in your header file:

@interface UIImage (MPMedia)

- (id) initWithMPMediaItem:(MPMediaItem*)item
   completionBlock:(void (^)(UIImage* delayedImagePreparation))completionBlock;

@end
sch
  • 27,436
  • 3
  • 68
  • 83
  • I entered your answer and it worked! I had the method lumped in with all my other methods in the header. Something else new to learn. Thank you sch and sosborn! – JimVision Mar 01 '12 at 02:57