iOS6 UIActivity tweetsheet text not populating - twitter

I'm using UIActivity class for the first time, with very little modification:
NSString *textToShare = #"my text";
UIImage *imageToShare = [UIImage imageNamed:#"myImage.png"];
NSArray *itemsToShare = #[textToShare, imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:nil];
When I test this, emails, messages, and Facebook are automatically populated with both the textToShare and the imageToShare, while only the image appears on the tweet sheet.
Apple UIActivity class documentation says UIActivityTypePostToTwitter will accept NSString, NSAttributedString, UIImage, AVAsset, and NSURL objects.
The WWDC video examples largely feature Facebook examples, and I've never dealt with Twitter before.
I thought it would populate just like the email/message/Facebook did, and I'm not sure where to go from here. Seems like it should be really simple, but my searches result in much more complex custom-Twitter problems and solutions.

"my text" was a few characters over the 140 character limit of a tweet. Shortened the text, tweet sheet populates.

Related

When Called From UIActivityViewController WhatsApp Freezes After a Recipient Is Selected

I am using UIActivityViewController to share my iOS app.
When WhatsApp is selected from the list of options, it takes me to the proper screen. I can move around, and all the buttons work.
However, once I select a recipient, WhatsApp freezes.
Does anyone know what's going on here? Has anyone encountered this bug before?
EDIT (Code Added)
Here's the code I'm using to call the UIActivityViewController:
- (void) sharePressed:(UIBarButtonItem *)sender {
NSString* shareText = #"Hello World!";
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[shareText] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
NSLog(#"This method ran: sharePressed");
}
It's as basic as it gets. It works for everything except WhatsApp.
try this code
- (IBAction)shareButton:(UIBarButtonItem *)sender
{
NSString *textToShare = #"Look at this awesome website for aspiring iOS Developers!";
NSURL *myWebsite = [NSURL URLWithString:#"http://www.codingexplorer.com/"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
I think the error was actually an internal problem with either whatsapp or UIActivityViewController because my other apps that use UIActivityViewController couldn't share on whatsApp last night. This morning though, even though I didn't change anything in my code, everything works perfectly!
I think is a bug in WhatsApp after yesterday update.
Update: You can send an NSUrl instead of NSString.

Customising UIActivity for UIActivityTypeMessage

I'm sharing an image and its description text using UIActivityType. I need to share the URL of the image if I choose SMS sharing option. How can I do that? Currently I'm sharing the image and data to Facebook and Twitter. How to send the URL in case that SMS option is selected?
You can share the image using SMS option in the same way that you are doing it with Facebook and Twitter.
The activityType for SMS is UIActivityTypeMessage. It is the built-in activityType.
So the only thing you need to do is provide image and image description as activityItems while creating your UIActivityController.
The code snippet is given below:
NSString *imageDescription = #"Image Description Goes Here";
UIImage *image = [UIImage imageNamed:#"Image_Name"];
NSArray *items = [NSArray arrayWithObjects: imageDescription,image,nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];

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:^{}];

Send a link in an email using UIActivityViewController

How do I send an email using UIActivityViewController with a quick message and a link? I have tried using an NSURL:
NSURL *url = [NSURL URLWithString:#"http://google.com/"];
And an NSString:
// String with Hyperlink syntax
NSString *stringURLHyperlink = #"Google";
// Plain text link out of desperation.
NSString *stringURLPlain = #"http://google.com/";
I am not using a custom UIActivity. The NSString/NSURL are being sent as activityItems:
NSArray *activityItems = #[link];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
Thanks everyone.
EDIT 1:
My apologies, I should have made my question clearer. How can I send a message and a clickable link in an email using UIActivityViewController?
This seems to work fine in iOS 7:
[[UIActivityViewController alloc] initWithActivityItems:#[#"<html><body><b>This is a bold string</b><br\\>Check out this amazing site: <a href='http://apple.com'>Apple</a></body></html>"] applicationActivities:nil];
If you share an object that conforms to the UIActivityItemSource protocol, then you will be able to specify what the email's subject should be too!
tl;dr: Use basic html in an NSString to wrap the desired email contents
In my case, I did not need to post a photo as long as an image was retrieved from the link I needed to share (just like when you post a link on your Facebook timeline and it automatically grabs a picture from that link, and the picture becomes the link). In order to do that, I figured out that if I posted only an URL it does not work. You have to post some initial text and then the URL, and you do so by putting the objects in that order within the activityItems array.
This is my working code:
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text."], [NSURL URLWithString:#"http://www.google.com"]];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeMessage];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
I also noticed that if you post a photo along these objects, it will not retrieve any image from the link.
I hope this helps.

UIActivityViewController cannot add image to imessage

I'm using UIActivityViewController to share image on ios 6 and my code
UIImage *shareImage = [UIImage imageNamed:#"myImage.png"];
// Init array
NSMutableArray *items = [NSMutableArray new];
[items addObject:#""];
[items addObject:shareImage];
// Add image to paste board
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
pasteboard.image = shareImage;
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
//This is an array of excluded activities to appear on the UIActivityViewController
activityVC.excludedActivityTypes = #[UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
Everything working fine but cannot paste shareImage to iMessage. I don't know why?
Thank for your help!
As others have said, iMessage only supports text, not images. Although it sounds like in iOS7, it does work.
I know personally I've gotten it to work with OvershareKit: https://github.com/overshare/overshare-kit .
It of course adds a bit of overhead but allows you to share with just about every medium there is with their slick interface/APIs.

Resources