IOS UIActivityViewController using UIActivityItemProvider forgets

I have a larger application that should be able to share multiple images. I implemented this using UIActivityViewController and UIActivityItemProvider to have asynchronous use of elements (so I need to prepare only one image at a time and do not need to fill the memory with all of them at once to separate them).

I was inspired by the Apple Airdrop example: Download AirdropSample

However, when using my application for sharing, for example. 9 images (for the Roll camera == "Saving 9 images"), only 4-7 images fall into the camera roll, there are no error messages at all. If I repeat it again and again, sometimes I get 5 images or 6 that seem random.

I can’t publish my application here, but I changed the above example so that it also accidentally “failed” with the delivery of all images to the Roll camera ...

If you download the sample above and replace 4 files, this will show the problem:

APLAsyncImageViewController.h:

#import <UIKit/UIKit.h>
#import "APLAsyncImageActivityItemProvider.h"

@interface APLAsyncImageViewController : UIViewController
@end

APLAsyncImageViewController.m:

#import "APLAsyncImageViewController.h"
#import "APLProgressAlertViewController.h"

NSString * const kProgressAlertViewControllerIdentifier = @"APLProgressAlertViewController";


@interface APLAsyncImageViewController ()

@property (strong, nonatomic) UIWindow *alertWindow;
@property (strong, nonatomic) APLProgressAlertViewController *alertViewController;
@property (strong, nonatomic) UIPopoverController *activityPopover;

@property (weak, nonatomic) IBOutlet UIButton *shareImageButton;

- (IBAction)openActivitySheet:(id)sender;

@end


@implementation APLAsyncImageViewController


- (IBAction)openActivitySheet:(id)sender
{
    NSMutableArray *itemArray = [[NSMutableArray alloc] init];
    for( int i = 0; i < 9;i++)
    {
        APLAsyncImageActivityItemProvider *aiImageItemProvider = [[APLAsyncImageActivityItemProvider alloc] init];
        [itemArray addObject: aiImageItemProvider];
    }

    //Create an activity view controller with the activity provider item. UIActivityItemProvider (AsyncImageActivityItemProvider superclass) conforms to the UIActivityItemSource protocol
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemArray applicationActivities:nil];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        //iPhone, present activity view controller as is
        [self presentViewController:activityViewController animated:YES completion:nil];
    }
    else
    {
        //iPad, present the view controller inside a popover
        if (![self.activityPopover isPopoverVisible]) {
            self.activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
            [self.activityPopover presentPopoverFromRect:[self.shareImageButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        }
        else
        {
            //Dismiss if the button is tapped while pop over is visible
            [self.activityPopover dismissPopoverAnimated:YES];
        }
    }
}
@end

APLAsyncImageActivityItemProvider.h:

#import <UIKit/UIKit.h>
@interface APLAsyncImageActivityItemProvider : UIActivityItemProvider
@end

APLAsyncImageActivityItemProvider.m:

#import "APLAsyncImageActivityItemProvider.h"
#import "UIImage+Resize.h"

@implementation APLAsyncImageActivityItemProvider


- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
    return [[UIImage alloc] init];
}

- (id)item
{
    UIImage *image = [UIImage imageNamed:@"Flower.png"];

    //CGSize imageSize;
    //imageSize.height = 1000;
    //imageSize.width = 1000;
    //image = [UIImage imageWithImage:image scaledToFitToSize:imageSize];

    return image;
}

- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size
{
    //The filtered image is the image to display on the other side.
    return [[UIImage alloc] init];
}

@end

( " ", "SHARE" ), 9 .

4 "APLAsyncImageActivityItemProvider.m", , .

, ? , , , .

,

+1
2

.

, , - "Write Busy". , , UIImageWriteToSavedPhotosAlbum ( Asset/Photos). , , .

/ . , [UIActivityItemProvider item] , . dispatch_semaphore_wait, NSCondition .. , ReactiveCocoa, waitUntilCompleted.

+1

, [UIImage imageWithImage:image scaledToFitToSize:imageSize] - GC , , . UIImage, , ?

, , , .

NSMutableArray *itemArray = [[NSMutableArray alloc] init];
for( int i = 0; i < 9;i++)
{
    UIImage *aiImage = [[[APLAsyncImageActivityItemProvider alloc] init] image];
    [itemArray addObject:aiImage];
}
0

All Articles