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:^{}];
Related
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.
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.
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:^{}];
Below given code, I'm sharing 1 text and 2 photos using UIActivityViewController. Then I choose Facebook for my sharing destination and it's shared on 2 separated posts on the feed for each photo but what I want is to share it in one single post with 1 text and 2 photos. How can I achieve this? I have done lot of search on here and found no proper answer. It seems to me that Facebook may have no clear way to do this, so it's like such an issue may lie on their side.
activityItems = #[self.textDetail.text, self.imageFileView1.image, self.imageFileView2.image];
UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
The issue was solved by either new iOS ver or Facebook's new way of handling activity items. Anyway it works as I expect now.
Try this:
NSString *message = #"msg To post";
NSMutableArray *postsImages=[[NSMutableArray alloc] init];
[postsImages addObject:message];
for (UIImage *img in collectionImageArray) {
[postsImages addObject:img];
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postsImages
applicationActivities:nil];
[activityVC setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
if([activityType isEqualToString:UIActivityTypePostToTwitter]){
//twitter selected
}
}];
[self presentViewController:activityVC animated:YES completion:nil];
I have a basic UIActivityViewController sharing some text and a URL. The sharing options are Email, SMS, Twitter, and Facebook. Everything works fine in iOS 6 but in iOS 7 when I choose Twitter or Facebook, without touching anything my device automatically closes my app, opens Safari and goes to the URL I am trying to share. What could be causing this?
Code (CustomActivityItemProvider is a subclass to customize text based on sharer):
if ([UIActivityViewController class]) { // if class exists = ios6+
// Create array for sharing
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:#"Text to share.\n"];
NSURL *urlToShare = iTunesShort ? iTunesShort : [NSURL URLWithString:iTunesLink];
NSArray *activityItems = #[textToShare, urlToShare];
// Show sharing view
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
So I still don't know why only shortened URLs were causing this problem, but a solution that took care of it was to include the urlToShare in the textToShare.
// Create array for sharing
NSString *urlToShare = iTunesShort ? iTunesShort : iTunesLink;
NSString *textWithUrl = [NSString stringWithFormat:#"Text to share.\n%#", urlToShare];
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
initWithStandardText:textWithUrl];
NSArray *activityItems = #[textToShare];