UIActivityView attach file to Email - ios

I've created an UIActivityView inside my iPad App but I don't know how to attach a file when sending an email. How can I do?

I think it will help you.
NSData *pdfData = [NSData dataWithContentsOfFile:pdfFilePath];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"Test", pdfData] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];

Related

How to pass API and fetched data to UIActivityViewCollector

I am using a table view and i am using it to display clips which i am fetching from core data. Now i have an API for clip path which will connect it to the server clips i want to pass clip id with that API and pass the clip name fetched from the core data.i have tried following thing to make it work but gives me error.I think i am doing it wrong. How would i do that.
//here is my code but it is giving me error. Can't pass it this way.
NSArray * activityItems = #[[NSURL URLWithString:#"http://example.com/view-videos.html?task=clip.details&id=%#",_fetchid]]; // this is giving me error and here i also want to send selected clip name with this API
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:videoToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToWeibo,UIActivityTypeCopyToPasteboard,UIActivityTypeMessage];
[self presentViewController:activityVC animated:YES completion:nil];
}
Try something like this. You are passing some other object not activityItems.
NSString *urlString = [NSString stringWithFormat:#"http://example.com/view-videos.html?task=clip.details&id=%#",fetchid];
NSArray * activityItems = #[[NSURL URLWithString:urlString]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter,UIActivityTypePostToWeibo,UIActivityTypeCopyToPasteboard,UIActivityTypeMessage];
[self presentViewController:activityVC animated:YES completion:nil];
If you want to share some video then also add that video in activityItems array object
Hope this will help you.

How to share text and image(both) on whatsapp using UIActivityController : Objective C?

UIImage * imageShare = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:trackImagePath]]];
NSURL *urlLink = [NSURL URLWithString:linkstr];
SharingActivityProvider * share = [[SharingActivityProvider alloc]initWithPlaceholderItem:#"Ghaneely Share!"];
share.sharelink = urlLink;
share.sharelinkText = shareString;
NSArray *objectsToShare = #[imageShare,share];
activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypeAssignToContact,UIActivityTypeAirDrop];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:TRUE completion:nil];
I want to share text and image (both) on WhatsApp just like Android by using UIActivityController. It used to work before when I used share without SharingActivityProvider. But I need to post different text on facebook, twitter,etc ,hence I am using ActivityProvider(which I think should not be the problem). Now with the code above it is sharing only image.
What could be the issue?
From this way you can share text and video to whatsapp :-
NSString *URLString=#"http://video.app.com/video.php?";
NSURL *VideoURL=[NSURL URLWithString:#“URLString ”];
NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:VideoURL,#"Hey, check out this video I've shared with you, it's awesome!", result1, nil];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
self.activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,UIActivityTypeAirDrop];
[self presentViewController:self.activityViewController animated:YES completion:nil];
try this may be it will help you.

Objective-C UIActivityViewController method for when use is done

I am using UIActivityViewController like so:
NSData *pdfData = [NSData dataWithContentsOfFile:filePath];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:#[pdfData] applicationActivities:nil];
activityController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityController animated:YES completion:^{}];
I am wondering if there is a method I can use for when the use is finished using the UIActivityViewController (Cancel, Message, Mail, etc.)
How would I go about doing this?
Use the completionWithItemsHandler property of the UIActivityViewController to specify code that should run when the user is done with it.
Reference: Determine which share extension was used

Sending image to whatsapp with ActivityVC

I'm trying to share an image and text.
But when i'm trying to share using whatsapp i dont see the image and it doesnt get sent (i do see it when i'm trying to share to facebook or mail...).
Whats going on?
- (void)shareImage:(UIImage *)image
{
NSString *sharedMsg=[NSString stringWithFormat:#"Hello world"];
UIImage* sharedImg=image;
NSArray* sharedObjects=[NSArray arrayWithObjects:sharedMsg, sharedImg, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:sharedObjects applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
}
#ozd,
if image Share then
see link : Share image/text through WhatsApp in an iOS app
& if Share Text
JBWhatsAppActivity Library: https://github.com/jberlana/JBWhatsAppActivity
using Below Code You can share Text , Link..etc, may be helpful to you.
WhatsAppMessage *whatsappMsg = [[WhatsAppMessage alloc] initWithMessage:#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en" forABID:#""];
NSArray *applicationActivities = #[[[JBWhatsAppActivity alloc] init]];
NSArray *excludedActivities = #[UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeMessage];
NSArray *activityItems = #[#"Hey , I would like you to experience this fabulous app which helps you to create , store and share your MOMENTS. You can add your voice message to every photo and moments too !!!\n\nDownload the app from https://play.google.com/store?hl=en", whatsappMsg];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = excludedActivities;
[self presentViewController:activityViewController animated:YES completion:^{}];

Add Facebook to UIActivityViewController shares

I am trying to let my iOS app to share using the UIActivityViewController, my problem is i can only share with Message and Mail . In other words the apps that are appear in the UIActivityViewController are only the Message and Mail .
How could I add the FaceBook or Twitter to them .
Here is my code
UIButton *shareButton=(UIButton*)sender;
UIActivityViewController *activityVC=[[UIActivityViewController alloc] initWithActivityItems:
#[#"Programmatically Shared post Just for testing ",
[ [videosList objectAtIndex:shareButton.tag ]videoUrl]]
applicationActivities:nil];
I am already logged in with FaceBook App and it is shown when i trying
to share using another app.
You're probably not logged in to Facebook or Twitter in the devices Settings. They won't show up here unless the user is logged in.
Looks like you are not attaching the URL perfectly :
NSString *shareText = #"Text";
NSURL *shareURL = [NSURL URLWithString:#"http://somewebsite.com"];
NSArray *items = [NSArray arrayWithObjects:
shareText,
_shareImage,
shareURL, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[activityViewController setValue:shareText forKey:#"subject"];
[self presentViewController:activityViewController animated:YES completion:nil];
NSArray* dataToShare = #[NSURL fileURLWithPath:#"file url"];
// ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController= [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];

Resources