我正在尝试通过与this类似的UIActivityViewController
分享图片。但是,如果我分享几张图片,Twitter和Facebook将会在UIActivityViewController
中消失。
有没有办法为Twitter和Facebook共享一个图像,多个图像作为附件邮件?
编辑:
// return different string depends on the type
CustomActivityItemProvider *textProvider = [[CustomActivityItemProvider alloc] initWithText:textContent url:url title:textTitle];
NSMutableArray *applicationActivities = [NSMutableArray array];
NSMutableArray *activityItems = [@[
textProvider,
image,
url
] mutableCopy];
// custom applicationActivities
...
// If add multiple images, facebook and twitter will not show up
for(int i = 0; i < [images count]; ++i)
{
if(images[i] != image) [activityItems addObject:images[i]];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[activityController setValue:textTitle forKey:@"subject"];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
有没有类似于UIActivityItemProvider
的方法?
答案 0 :(得分:0)
与textActivityItemProvider
类似的方式我最终会使用:
ImageActivityItemProvider.h
#import <UIKit/UIKit.h>
@interface ImageActivityItemProvider : UIActivityItemProvider
@property (nonatomic, strong, readonly) UIImage *image;
@property (nonatomic, readonly) NSInteger index;
@property (nonatomic, readonly) NSInteger shouldShowIndex;
- (instancetype)initWithImage:(UIImage*)image index:(NSInteger)index shouldShowIndex:(NSInteger)shouldShowIndex;
@end
ImageActivityItemProvider.m
#import "ImageActivityItemProvider.h"
@interface ImageActivityItemProvider ()
@property (nonatomic, strong) UIImage *image;
@property (nonatomic) NSInteger index;
@property (nonatomic) NSInteger shouldShowIndex;
@end
@implementation ImageActivityItemProvider
- (instancetype)initWithImage:(UIImage*)image index:(NSInteger)index shouldShowIndex:(NSInteger)shouldShowIndex
{
// make sure the placeholder is nil instead of the image
self = [super initWithPlaceholderItem:nil];
if (self)
{
self.image = image;
self.index = index;
self.shouldShowIndex = shouldShowIndex;
}
return self;
}
- (id)item
{
if (
[self.activityType isEqualToString:UIActivityTypeMail] ||
self.index == self.shouldShowIndex
)
{
return self.image;
}
return self.placeholderItem;
}
@end