When Called From UIActivityViewController WhatsApp Freezes After a Recipient Is Selected - ios

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.

Related

Show all options in UIActivityViewController

I have some trouble with create native share dialog.
My goal is share link of my product by native view controller, but I can't do it. I'm trying test code:
NSURL *google = [NSURL URLWithString:#"http://google.com"];
NSArray *activityItems = #[google];
UIActivity *activity = [UIActivity new];
UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:#[activity]];
activityViewControntroller.excludedActivityTypes = #[];
[self presentViewController:activityViewControntroller animated:true completion:nil];
And I get no FB and twitter icons. In the other hand, I can see it in safari both icons and when I'm touching it I see "You need configure your account before post".
So, I want the same behavior: icons for all most-popular social networks such as VK, FB, twitter; messengers like whatsapp, viber and telegram. If some of them is not installed I want dialog "You have to log in before" and redirect to safari (e.g. for FB) to log in or open appstore (e.g. for telegram or viber) to install; otherwise I want post message with my link.
I see it like this: exclude all types from activity vc, than forcibly add all icons I need and check each of them on click manually. But in apple docs I've read that "you have to use native behavior for native items instead of create custom". So, will it be correct? Or there are other ways to solve this?
Try this
-(void)clickShare:(UIButton *)sender{
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text."], [NSURL URLWithString:#"http://www.google.com"]];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
}
this code working in my project.

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

UIActivityViewController Automatically 'Clicking' Link iOS 7

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];

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