Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oh now I see it.. sry. You are using an asynchronous block to get the image from the asset library. But right after starting that operation, you are returning <code>xImage</code>. But the asynchronous operation will finish later. So you are returning nil.</p> <p>You need to change your architectur to smth like this:</p> <p>In your .h file you need two new members:</p> <pre><code>NSMutableArray* mArrayForImages; NSInteger mUnfinishedRequests; </code></pre> <p>In your .m file do smth like that:</p> <pre><code>- (void)sendReportReport { // save image count mUnfinishedRequests = [fetchedPhotos count]; // get fetchedPhotos [...] // first step: load images for (NSManagedObject *managedObject in fetchedPhotos ) { [self loadImage:photo.referenceURL]; } } </code></pre> <p>Change your getImage method to loadImage:</p> <pre><code>- (void)loadImage:(NSString *)URLReference { NSURL *asseturl = [NSURL URLWithString:URLReference]; ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { // get the image ALAssetRepresentation *rep = [myasset defaultRepresentation]; CGImageRef iref = [rep fullScreenImage]; if (iref) { [mArrayForImages addObject: [UIImage imageWithCGImage:iref]]; } else { // handle error } [self performSelectorOnMainThread: @selector(imageRequestFinished)]; }; ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) { NSLog(@"Error fetching photo: %@",[myerror localizedDescription]); [self performSelectorOnMainThread: @selector(imageRequestFinished)]; }; // create library and set callbacks ALAssetsLibrary *al = [DetailsViewController defaultAssetsLibrary]; [al assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock]; } </code></pre> <p>Create a new callback method:</p> <pre><code>- (void) imageRequestFinished { mUnfinishedRequests--; if(mUnfinishedRequests &lt;= 0) { [self sendMail]; } } </code></pre> <p>And an extra method for finally sending the mail, after getting the images:</p> <pre><code>- (void) sendMail { // crate mailcomposer etc [...] // attach images for (UIImage *photo in mArrayForImages ) { NSData *imageData = UIImageJPEGRepresentation(photo, 0.5); [mailer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:[NSString stringWithFormat:@"a.jpg"]]; } // send mail [...] } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload