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];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemArray applicationActivities:nil];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityViewController animated:YES completion:nil];
}
else
{
if (![self.activityPopover isPopoverVisible]) {
self.activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.activityPopover presentPopoverFromRect:[self.shareImageButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
[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"];
return image;
}
- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size
{
return [[UIImage alloc] init];
}
@end
( " ", "SHARE" ), 9 .
4 "APLAsyncImageActivityItemProvider.m", , .
, ? , , , .
,