I am enable to get the answer from last couple of Weeks that
Actually I have 1 tableview contains some text, and I have Sharing bar button if iClicked that Sharing Barbutton At Index i need to Share that text to Email,FB,WhatsuP,and other that are Installed and supported to send text.
finally my requirement is when I clicked the bar button, i need to open the view that contains the list of Installed Apps in our device(Email,FB,WhatsUp,etc)That are supported to send text.
and When I clicked The Item in the List, text should send to That App.
I have no idea and I am searching for it from few couple of weeks
Please Help me
Thanks
Use UIActivityViewController
NSString *shareText = #"some text to share";
NSURL *url = [NSURL URLWithString:#"http://www.someurl.com"];
NSArray *itmes = #[shareText, items];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
If you wish you can also exlude some of the items in the activityVC like
activityVC.excludeActivityTypes = #[UIActivityTypePostToFlickr, UIActivityTypePostToTensentWeibo];
// and as many more you like
Related
I have a simple UIActivityViewController to share a data file and some text.
The text is required because, since iOS 13, it's no longer intuitive how to open a file sent in messages.
My issue is, when I choose Messages as the option to send, it attaches the file, but not the text.
Prior to iOS13, it used to send the file in one message, and the text in a follow up.
If I share to Mail, or save to Files, both the text and the data are included.
If I share an NSURL that's simply a web address, and text, then both are shared in the same message.
It's only when I try to share an NSURL that points to a data source, and text, that only the data file is sent.
Here's my code:
//Get NSURL for file
NSURL *dataUrl = [AppData data:zippedData toPlnUrl:fileName]; //zipped data
NSString *subject = #“PolyNome files”;
NSString * textToShare = #"Check out these PolyNome Presets. Learn how to import here ->”];
NSURL *website = [NSURL URLWithString:#"https://polynome.net/importing"];
NSArray *objectsToShare = #[textToShare,website,dataUrl];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[activityVC setValue:subject forKey:#"subject"];
activityVC.modalPresentationStyle = UIModalPresentationPopover;
activityVC.popoverPresentationController.barButtonItem = self.shareButton;
[self presentViewController:activityVC animated:YES completion:nil];
So, for example, if NSArray *objectsToShare = #[textToShare,website]; then that works and both text and url are included in one message.
As soon as I add dataUrl as an element at any position in the array, then that's the only thing that gets shared in messages - all other things are omitted.
This is driving me crazy since the only reason I need to include the import instructions is because iOS 13 made it very complicated to import the file from messages (you have to tap the avatar at the top of messages, tap "info", find "attachments", tap an attachment, then tap the share button, then choose "More...", then choose the app.)
Any advice much appreciated!
My iOS is 8.1.2 and I am using the UIActivityViewController for social sharing.
I click on a button and allow the UIActivityViewController to present
- (IBAction)UIActivityTypeButtonClick:(id)sender {
NSString* text=#"I am sharing this text";
NSArray* sharedArray=#[text];
UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
activityVC.excludedActivityTypes=#[];
[self presentViewController:activityVC animated:YES completion:nil];
}
I am getting this
I am getting Message, Twitter, Mail, WhatsApp and a More button.
On clicking More I get this.
Where is FACEBOOK. I have the facebook app in my iPhone and it is setup with my ID too in settings. But facebook never shows up here. Twitter does. Is this a bug or what? Please suggest
Thanks
I first saw this when Facebook updated their app on April 24th. Plain text sharing to Facebook isn't working as long as the Facebook app is installed. After you delete it, it's available again.
If you try to share a URL or an image together with the plain text, you will see Facebook as an option but the text field will be blank. The image or URL will attach without a problem.
I posted a sample project that reproduces this problem on github:
https://github.com/djr/UIActivityViewController-Facebook
This is not an answer, but it's pretty clear that the problem is caused by the Facebook app.
EDIT:
It's not ideal, but I created a workaround. Don't forget that you will need to attach an image or a URL for this to work.
Detect if the user has the Facebook app installed. If they do, then give them some type of informational message.
BOOL facebookIsInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]];
BOOL isUserLoggedInWithFacebook = [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
if(isUserLoggedInWithFacebook && facebookIsInstalled)
{
// Explain that they have to copy and paste in order to share on Facebook
}
Create a subclass of UIActivityItemProvider and override
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
NSString *stringToShare = #"string to share";
if([activityType isEqualToString:UIActivityTypePostToFacebook] ||
[activityType isEqualToString:#"com.facebook.Facebook.ShareExtension"] ||
[activityType.lowercaseString rangeOfString:#"facebook"].length)
// Because who knows when they are going to change the activityType string?
{
// Automatically copy the text for them
[[UIPasteboard generalPasteboard] setString:stringToShare];
}
return stringToShare;
}
Tell the user that they have to paste into the Facebook text field in order to share.
Blame it on Facebook.
I confirm what djr reported - if you have the FB app text is no longer shared. I deleted the FB app and now sharing both text and image works.
Facebook would like you to use their SDK. They have blocked the ability to set initial text. (Not sure how.) Check out my answer in a similar post:
UIActivityViewController for Facebook not Showing Default Text
The desired solution (from Facebook) is to use their SDK.
NSString* text=#"I am sharing this text";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.website.com/"];
// UIImage * myImage =[UIImage imageNamed:#"myImage.png"];
NSArray* sharedArray=#[text,myWebsite];
UIActivityViewController * activityVC=[[UIActivityViewController alloc]initWithActivityItems:sharedArray applicationActivities:nil];
NSArray *excludedActivities = #[];
activityVC.excludedActivityTypes=excludedActivities;
[self presentViewController:activityVC animated:YES completion:nil];
To show facebook sharing button you must add a image to the array of activity items... this may be a bug on apple side but i've not seen any open radar about this issue.
Also note on iOS 8.3 text can't be added to facebook for some reason. when adding text you only be presented to a blank textfield.
UIImage *image = [UIImage imageNamed:#"__some_image__file"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[image]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
The Photos app in iOS 7 allows you to select multiple photos, tap "Share" and be presented with a document interaction controller with the appropriate options for multiple items.
The Camera app goes one further and even updates the document interaction controller's options in real time as you select and deselect photos.
However, the UIDocumentInteractionController class seems only to allow for a single URL parameter.
Is it possible to do what the Photos and Camera apps do using public API?
- (void)showShareDialog
{
UIImage *image = [UIImage imageWithCGImage:self.imgView.image.CGImage];
NSArray* dataToShare = #[image, image2, image3]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{
}];
}
I think this should help
Store the URLs of the selected items in an array. You can change the actions displayed depending upon the number of elements in the array. After the user makes his/her selection, you can loop through the URLs and apply the selected action.
I am trying to share a text (or an URL) and an image with AirDrop and it seems it sends only the image. It works fine with other sharing activities (Facebook, Twitter, Mail, Message etc.). Is it possible to share two items with AirDrop?
Here is how I use the UIActivityViewController:
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[self.activityItem, self.attachedImage] applicationActivities:nil];
self.attachedImage is an UIImage and self.activityItem is a subclass of UIActivityItemProvider which returns different text for different activity types in delegate method
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
Does anyone have an idea? Thanks!
EDIT:
I also tried without subclassing UIActivityItemProvider and passed directly some text. Didn't work.
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"some text", self.attachedImage] applicationActivities:nil];
As a note, it works if I want to share multiple texts OR multiple images (UIImage):
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[#"text 1", #"text 2"] applicationActivities:nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[attachedImage1, attachedImage2] applicationActivities:nil];
Try this code
NSString *text= #"text to share";
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:text];
NSArray *activityItems = #[textToShare,self.attachedImage];
Use activityItems array in activity view controller.
Posted the same question on Apple Dev Forums: https://devforums.apple.com/message/937697#937697
Got this answer:
Currently not possible. AirDrop only lets you send sets of single
items. If you are trying to send it to an instance of your own app on
the other side, you could instead create a fileformat (a
bundle/package would probably be suitable here) and embed all the
different types with the file. Then on the receiving side you can
extract the different types out of the file.
I am using a cocoa touch UIActivityViewController, and I would like to post an image thumbnail with a link that can be touched or clicked, and that would take them to the link. If possible I would like the link to not appear in the posts's body.
The user should also be able to write a custom message for this post.
For now I only seem to be able to post a link with a picture, but picture is not the link.
Thanks,
Sam.
I dunno if that's what u want but try this
NSString *someText = #"TEST!";
UIImage *shareImage = [UIImage imageNamed:#"someimage.png"];
NSURL *shareUrl = [NSURL URLWithString:#"http://www.somepage.com"];
self.dataToShare = #[self.someText,shareImage,shareUrl];
self.activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:self.dataToShare
applicationActivities: nil];
Hope it helps! :D