How do I use UIActivityItemProvider to send an email with attachment with UIActivityViewController?
i'm sending email with attachment without ItemProvider. its working well :-)
NSMutableArray *selDocs = [[NSMutableArray alloc] init];
for (Document *theDoc in self.selectedDocs) {
NSURL *fileUrl = [NSURL fileURLWithPath:theDoc.filePath];
[selDocs addObject:fileUrl];
}
NSArray *postItems = [NSArray arrayWithArray:selDocs];
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];
[avc setValue:@"Your email Subject" forKey:@"subject"];
avc.completionHandler = ^(NSString *activityType, BOOL completed){
NSLog(@"Activity Type selected: %@", activityType);
if (completed) {
NSLog(@"Selected activity was performed.");
} else {
if (activityType == NULL) {
NSLog(@"User dismissed the view controller without making a selection.");
} else {
NSLog(@"Activity was not performed.");
}
}
};
[self presentViewController:avc animated:YES completion:nil];
How to set mail subject with UIActivityItemProvider
Define your custom item provider:
@interface CustomProvider : UIActivityItemProvider
@end
Add to your implementation:
@implementation CustomProvider
// Some other code ... -(id)item and etc.
- (NSString *) activityViewController:(UIActivityViewController *)activityViewController
subjectForActivityType:(NSString *)activityType
{
return @"A dummy Title";
}
@end
Notice that UIActivityItemProvider
will automatically conform to UIactivityItemSource
protocol. The difference is, you don't have to implement those @required
API for UIactivityItemSource
protocol.
How to set email attachment file name using UIActivityViewController email sharing
try this...
NSString *text = @"write text here";
UIImage *image = [UIImage imageNamed:@"your image name"];
NSArray *activityItems = [NSArray arrayWithObjects:text,image , nil];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
how to share only through email using UIActivityViewController using swift
Just add excludedActivityTypes to remove all the other activity except email
yourActivityViewController.excludedActivityTypes = [ UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo,UIActivityTypeAirDrop]
Add subject
yourActivityViewController.setValue("Your email Subject" , forKey: "subject") ;
Suggession :-
You can also use MFMailComposeViewController to send email
var picker = MFMailComposeViewController()
picker.mailComposeDelegate = self
picker.setSubject(subject.text)
picker.setMessageBody(body.text, isHTML: true)
presentViewController(picker, animated: true, completion: nil)
More References :-
How do I use UIActivityItemProvider to send an email with attachment with UIActivityViewController?
iOS 8 - Disable iCloud Photo Sharing Activity
Related Topics
Error in iOS 10:Unable to Copy Asset Information from Https://Mesu.Apple.Com/Assets/ for Asset Type
Scanning Barcode or Qr Code in Swift 3.0 Using Avfoundation
How to Determine If the Sim/Phone Number Has Changed
Workaround for Rounded Corners of Grouped Uitableview, iOS7
Skspritenode Position in Universal Game
How to Create Custom View Programmatically in Swift Having Controls Text Field, Button etc
Accessing the Settings App from Your App in iOS 8
Cannot Show Automatic Strong Passwords for App Bundleid
Reload Section Without Reloading Section Header
Customizing the Colors of a Uisegmentedcontrol
How to Reset the Application Data After Each Test with Xcode 7 UI Testing
iOS 10 Heading Arrow for Mkuserlocation Dot
Detect Moment When Newline Starts in Uitextview
Core Data: Delete All Objects of an Entity Type, Ie Clear a Table