How to Use Uiactivityitemprovider to Send an Email with Attachment with Uiactivityviewcontroller

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



Leave a reply



Submit