Im using UIActivityViewController to show share. In the list when i select Mail app the subject and body is set properly and where as in Gmail app its empty.
- (void)shareAVideoWithSubject:(NSString*)subject Link:(NSString *)string onViewController:(UIViewController *)viewController fromView:(UIView *)view {
_activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[string]
applicationActivities:nil];
_activityViewController.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypeAirDrop];
[_activityViewController setValue:subject forKey:@"subject"];
UIWindow *window = [[[UIApplication sharedApplication] delegate]window];
//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if(!viewController){
viewController = ((SWRevealViewController*)window.rootViewController).presentedViewController;
}
[viewController presentViewController:_activityViewController
animated:YES
completion:nil];
}
//if iPad
else
{
// Change Rect to position Popover
popup = [[UIPopoverController alloc] initWithContentViewController:_activityViewController];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:view];
[popup presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
I have check the below two questions on StackOverFlow.
These are not answer to my question because they add up new activity in list, rather i want the iOS shows the all shareable apps. In that case Gmail share body is going empty.
Thanks in advance. Adding the screenshots,
[_activityViewController setValue:subject forKey:@"subject"];
Is undocumented way to set subject of email.
Correct way to set body and subject (iOS 7.0 and later) - implement UIActivityItemSource
protocol on item to share.
// EmailItemProvider.h
@interface EmailItemProvider : NSObject <UIActivityItemSource>
@property (nonatomic, strong) NSString *subject;
@property (nonatomic, strong) NSString *body;
@end
// EmailItemProvider.m
#import "EmailItemProvider.h"
@implementation EmailItemProvider
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return _body;
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
return _body;
}
- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType {
return _subject;
}
@end
And than present it:
EmailItemProvider *emailItem = [EmailItemProvider new];
emailItem.subject = @"Subject";
emailItem.body = @"Body";
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[emailItem]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
This will set body and subject on mail app, but seems like Gmail app ignores subject and set it equal to body.
Important: Seems like there is a bug in Gmail App. Passing &
character make message subject and body to be empty. Use &
instead. Other special characters are not tested.