Im refactoring my code for using UIActivitiy and UIActivityProvider. I ran into a problem when Twitter no longer displayed in the UIActivityViewController.
I found that Twitter will not appear if more than one of my UIActivityProvider classes has assigned a PlaceholderItem to a UIImage object. No other activity is likely to be affected by placeholder classes that cannot be used.
For context, there is some setup code:
NSArray *applicationActivities = @[reviewActivity, myEmailActivity]; NSArray *excludeActivities = @[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToWeibo]; UIActivityItemProvider *screenshotProvider = [[ScreenshotActivityProvider alloc] initWithView :self.scrollView]; UIActivityItemProvider *textProvider = [[TextActivityProvider alloc] initWithExchangeDoc:self.docItem]; UIActivityItemProvider *imageProvider = [[ImageActivityProvider alloc] initWithExchangeDoc:self.docItem]; NSArray *activityItems = @[textProvider, screenshotProvider, imageProvider]; applicationActivities:applicationActivities]; UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:applicationActivities];
UIActivityItemProvider Im Example:
- (id)initWithExchangeDoc :(ExchangeDoc *)docItem { self = [super initWithPlaceholderItem:[UIImage new]]; _docItem = docItem; return self; } - (id)item { if ([self.activityType isEqualToString:UIActivityTypePostToTwitter]) { return self.docItem.thumbImage; } else { return nil; } }
The problem is initWithPlaceholderItem. I have another UIActivityProvider that identifies UIImage as a placeholder class.
I thought the goal of the suppliers of custom products was that my class could decide after starting UIActivityViewContrller which data was sent. In my case, my screenshot provider does not provide anything for Twitter. Why does iOS look at my placeholder and decide not to serve Twitter as a viable activity? My providers will sort who gets the delivery of the image based on the type of activity.
The docs talk about this placeholderItem:
An object that can stand for the real object that you plan to create. The contents of the object may be empty, but the class of the object must match the class of the object that you plan to provide later.
Obviously this does not work for me regarding Twitter. As an experiment, I replaced all placeholderItems with empty NSStrings and Twitter, and all other actions were great.
Does anyone know what these placeholderItems are used for and will their wrong class have any negative effect?
Too bad it took so long. I appreciate your help.