36

This bug is fixed by WhatsApp team on 23rd May, 2016 (build no. 2.16.4).

Unable to share NSString object using UIActivityViewController to WhatsApp.

I tried to share using below code. But once contact is selected from the list, it shows an alert displaying "This item cannot be shared. Please select a different item."

CODE

NSString *shareText = @"Temp text to share";
NSArray *itemsToShare = @[shareText];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];

I am facing this problem after updating WhatsApp to version 2.16.2

santhu
  • 4,796
  • 1
  • 21
  • 29
  • Did you figure it out ? Because even I am facing the same problem, It used to work properly till the last update of Whats App , but now its not ! – Irshad Qureshi Apr 15 '16 at 07:27
  • Same problem here. It's really frustrating. – pAkY88 Apr 15 '16 at 19:29
  • Nope. Sent a mail to whatsapp support team about this product issue. Not a reply since 4 days. No idea what to do but for temporary fix i just allow sharing link now. – santhu Apr 16 '16 at 08:27
  • Sure it's because of whatsapp and their native support for ActivityViewController? – Mark Molina Apr 18 '16 at 14:38
  • 2
    After playing a lil bit it seems whatsapp won't allow you to share directly text. But it allows you to share urls, videos, images, etc. So (at least in our case) we were sharing Text with embedded url and we replaced it to: `@[NSURL(***), "share Text"];` so that whatsapp only takes the url but the rest of apps take the text too. – Eli Kohen Apr 22 '16 at 09:58
  • After my testing I have to thank @EliKohen for the info. Hope this changes in the future :) – Happiehappie Apr 25 '16 at 13:44
  • Having the same issue any recent update on this? – Jigar Fumakiya Aug 12 '21 at 14:36

7 Answers7

21

Received a response from WhatsApp team

- WhatsApp Support -

Hi,

Sorry for the delay! We have received many emails recently, and we do our best to answer them all. Thank you for your patience.

Thank you for informing us about the issue; it will be fixed in a future version of WhatsApp. Unfortunately, we cannot comment on any future timelines, sorry. Thank you for your continued patience and support of WhatsApp.

Cheers, Hans

So, they acknowledge the bug and will fix this in the next release.

Possible Workarounds =>

  • Till then one can use UrlSchemes to share plaintext+url. Follow Spydy's answer.
    OR
  • One can create subclass of UIActivity with activityCategory as UIActivityCategoryShare with whatsapp icon. Then when user selects it, will use urlschemes to share text. For this use JBWhatsAppActivity
    OR
  • Just share NSUrl object for sharing url. Once the fix is done you can revert to sharing plain text and url.
Community
  • 1
  • 1
santhu
  • 4,796
  • 1
  • 21
  • 29
9

You might wanna try sharing the local URL of the item you're trying to share. For example, if you'd like to share a pdf, don't try to share it's NSData or Data object, WhatsApp still does show that error for that. Instead, if you share the local URL of it, WhatsApp recognizes it and shares it well.

I must note that many apps including native Mail, Gmail, Slack, GDrive etc. do recognize the pdf if you try to share the Data object.

For example:

After downloading a PDF, bind its URL into a variable called fileURL:

var fileURL = URL(string: url)
    let destination: DownloadRequest.DownloadFileDestination = { _, _ in
        let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
        fileURL = documentsURL.appendingPathComponent("AWESOME_PDF.pdf")
        return (fileURL!, [.removePreviousFile, .createIntermediateDirectories])
    }

Then you can simply share the fileURL instead:

let activityViewController = UIActivityViewController(            
      activityItems: [fileURL!],
      applicationActivities: nil
)

WhatsApp will recognize the PDF.

Hope this helps!

Arnab
  • 4,216
  • 2
  • 28
  • 50
Mert Kahraman
  • 445
  • 6
  • 10
  • I can send the pdf through WhatsApp with this solution. But from other iOS devices that pdf is opening but not from the Android. Any idea, why? – Soumen Oct 13 '19 at 10:50
8

have faced same issue after updating whatsapp. Even you press "cancel" on whatsapp still completion block shows success. i have resolved it by using "WFActivitySpecificItemProvider" and "WFActivitySpecificItemProvider"when sharing on whatsapp then dissmiss activityViewController and share via ur. You can pull WFActivitySpecificItemProvider, activityViewController classes from https://github.com/wileywimberly/WFActivitySpecificItemProvider

here is my code

- (void)share{

NSString *defaultMessage = @"your message may contain url";

// Use a dictionary
WFActivitySpecificItemProvider *provider1 =
[[WFActivitySpecificItemProvider alloc]
 initWithPlaceholderItem:@""
 items:@{
         WFActivitySpecificItemProviderTypeDefault : defaultMessage,
         UIActivityTypePostToFacebook : defaultMessage,
         UIActivityTypeMail : defaultMessage,
         UIActivityTypeMessage : defaultMessage,
         @"com.linkedin.LinkedIn.ShareExtension":defaultMessage,
         UIActivityTypePostToTwitter : defaultMessage

         }];


// Use a block
WFActivitySpecificItemProvider *provider2 =
[[WFActivitySpecificItemProvider alloc]
 initWithPlaceholderItem:@""
 block:^(NSString *activityType){

     if ([activityType isEqualToString:@"net.whatsapp.WhatsApp.ShareExtension"]) {


         [avc dismissViewControllerAnimated:NO completion:nil];

         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{



             NSString *string = [NSString stringWithFormat:@"whatsapp://send?text=%@",defaultMessage];
             NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
             [[UIApplication sharedApplication] openURL: url];


         });
     }

     return defaultMessage;
 }];


avc = [[UIActivityViewController alloc]
       initWithActivityItems:@[provider1, provider2]
       applicationActivities:nil];

[avc dismissViewControllerAnimated:YES completion:nil];
[avc setValue:sharingHeader forKey:@"subject"];

[avc setCompletionHandler:^(NSString *activityType, BOOL completed) {

    if (activityType) {


        NSLog(@"activity: %@ completed: %@",activityType,completed ? @"YES" : @"NO");


    } else {


        NSLog(@"No activity was selected. (Cancel)");
    }

}];

[self presentViewController:avc animated:YES completion:nil];
}
Waseem Sarwar
  • 2,645
  • 1
  • 21
  • 18
  • Your case may be different, in my case i have to show one share button for all kinds of sharing apps installed in my phone. so above code works for my case. – Waseem Sarwar Apr 14 '16 at 12:08
  • 2
    I am thinking along same lines. I will create subclass of UIActivity with activityCategory as UIActivityCategoryShare with whatsapp icon. Then when user selects it, will use urlschemes to share text. But i will wait for sometime till i get a reply from whatsapp product team. – santhu Apr 14 '16 at 12:32
  • 2
    Please let me know the Whatsapp team says. Thanks – pAkY88 Apr 15 '16 at 19:34
  • 1
    We are facing the same issue here, so let us know once you receive a reply from Whatsapp – Iphone User Apr 16 '16 at 17:37
2

WhatsApp has fixed this bug in the their update dated 23rd May, 2016 (build no. 2.16.4).

It hasn't been reported by official sources, but I have tested it in my code - works fine.

  • There are still issues with this, if you use 1Password for example and share a password from your vault with WhatsApp the error message will appear when you select a person to sent it to. – RichAppz May 31 '16 at 12:24
0

With the latest version of whatsapp, Now we can not share both text and URL at the same time.

I tried the below code

NSArray *activityItems= @[someText,[NSURL URLWithString:@"http://www.google.com"]];

With this code i am able to share only the URL link, the whatsApp filtered out the "someText" text.

but the other share apps(SMS etc) able to share both text and url.

hope WhatsApp fixes this issue soon.

Avaan
  • 4,709
  • 1
  • 10
  • 13
  • do u really think this answers it while other answers can't. Please readout other answers before posting another answer. – santhu May 01 '16 at 12:25
0

Ran into this problem with a custom UIActivityItemSource where I was passing back kUTTypeData that most providers understand for the dataTypeIdentifierForActivityType delegate method instead of kUTTypeText. Simple case overrides fixed the issue in my case. Just another reason the error above could be popping if anyone sees it.

open func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: UIActivityType?) -> String {
    switch activityType {
    case UIActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"):
        return kUTTypeText as String
    default:
        return kUTTypeData as String
    }
}
Mark Thormann
  • 2,522
  • 1
  • 21
  • 23
-1

I'm not sure about your question... Do you want just send text by whatsapp? If yes, you don't need use UIActivityViewController. Just use urlschemes.

Something like that:

NSString *string = @"whatsapp://send?text=<YOUR MESSAGE>";
NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: ];

You also can check if the user have whatsapp installed

if ([[UIApplication sharedApplication] canOpenURL: url]) {
   // wahtsapp installed
} else {
   // whatsapp not installed
}

Look this question: Share image/text through WhatsApp in an iOS app

Community
  • 1
  • 1
Wagner Sales
  • 1,448
  • 2
  • 10
  • 14
  • 3
    I know this. But i am not looking to use url schemes. Because its three taps away from sharing and looks lengthy process. I am more worried why WhatsApp native share extension is not working the way it used to work before. Please try it once and let me know if its working for you. Previously i used to share plane text NSString object which contains custom message and link. Now it doesn't even support plain text messages. – santhu Apr 13 '16 at 16:49
  • Hummmm... Interesting. I'll look for about WhatsApp native share extension. – Wagner Sales Apr 13 '16 at 16:55
  • Your code just prove this url which given as string object can assign NSURL . It's not related about Whatsapp.. – Onder OZCAN Apr 20 '16 at 08:51
  • It's an way to send whatsapp msg... Look the url scheme. @InnaKamoze – Wagner Sales Apr 25 '16 at 18:18
  • 1
    That's not solving a problem, you need to add a row in to plist as an array "LSApplicationQueriesSchemes" and insert a row as string "whatsapp" instead URL Scheme works. – Onder OZCAN Apr 26 '16 at 07:40
  • Just adding "whatsapp" to "LSApplicationQueriesSchemes" solved my problem of sharing text. – neowinston Aug 25 '16 at 20:05