jberlana / JBWhatsAppActivity

JBWhatsAppActivity is a UIActivity subclass that provides an “Share in WhatsApp" action to a UIActivityViewController.
Other
96 stars 16 forks source link

Can share on WhatsApp. #1

Closed hernangonzalez closed 11 years ago

hernangonzalez commented 11 years ago

Hello, I have added a class method to verify if the activity can take place. Thanks.

jberlana commented 11 years ago

Hi Hernan,

Actually that check is already done on - (void)prepareWithActivityItems:(NSArray *)activityItems and you have to check with the complete URL because previous versions of WhatsApp responds to whatsapp:// but not with send, abid or text params.

Anyways, I'm gonna change this method a little in order to no display the Whatsapp icon on the UIActivityController when no action can be done instance of display a icon that no produce actions, as is happening now.

Thanks!

hernangonzalez commented 11 years ago

Hi,

I wanted something handy that would not imply much from the user. I took the idea from your demo project where you have:

    if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"]]) { ... }

So, that check can be done with the lib:

    if ([JBWhatsAppActivity canShareOnWhatsApp]) { ... }

Maybe improving support for older versions would work.

Regards, Hernán.

jberlana commented 11 years ago

Hi,

good point, but maybe the best solution is that the UIActivity will be smart enough to not crash if can't open the link, and not worry the user to do that checks.

I just updated the demo project and now you can add JBWhatsAppActivity always to your UIActivityViewController and the one only show the WhatsApp button if can open the URL.

WhatsAppMessage *whatsappMsg = [[WhatsAppMessage alloc] initWithMessage:_messageTextField.text forABID:_abidTextField.text];

NSArray *applicationActivities = @[[[JBWhatsAppActivity alloc] init]];
NSArray *excludedActivities    = @[UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeMessage];
NSArray *activityItems         = @[_messageTextField.text, whatsappMsg];

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = excludedActivities;

[self presentViewController:activityViewController animated:YES completion:^{}];

How do you see that? Best regards

hernangonzalez commented 11 years ago

Yes, much better.I prefer not to present the user with an option he won't be able to use. That's the safest choise for the lib. I would also like not to do anything on my code. Just not to create the objects. Thanks!