8

In my app i want to create a share button with WhatsApp,Facebook,Twitter,Mail like this.

Here is my code

-(IBAction)share:(id)sender
{
NSString *shareText = @"Hi This is a Reward Game App";
NSArray *itemsToShare = @[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo,UIActivityTypePostToTwitter,UIActivityTypePostToFacebook,UIActivityTypeMail,UIActivityTypeMessage,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo];
[self presentViewController:activityVC animated:YES completion:nil];
}

I'm writing this code my simulator display like this,

enter image description here

It shows only mail and facebook icons, i want whatsup icon message like this nore.

Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
User558
  • 1,165
  • 1
  • 13
  • 37
  • Possible duplicate of [How to add custom buttons to UIActivityViewController?](http://stackoverflow.com/questions/20029520/how-to-add-custom-buttons-to-uiactivityviewcontroller) – RJV Kumar Jan 22 '16 at 07:11
  • 2
    You can't see all application in simulator. You have to run your app in device – kb920 Jan 22 '16 at 09:02

3 Answers3

16
-(IBAction)shareAction:(id)sender
 {    
        NSArray* sharedObjects=[NSArray arrayWithObjects:@"sharecontent",  nil];
        UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:sharedObjects applicationActivities:nil];
        activityViewController.popoverPresentationController.sourceView = self.view;
        [self presentViewController:activityViewController animated:YES completion:nil];
 }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
0

Swift 4.2

func shareMessage(message: String, link: String) {
    if let link = NSURL(string: link) {
        let objectsToShare = [message, link] as [Any]
        let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        present(activityVC, animated: true, completion: nil)
    }
}

call this function :

shareMessage(message: "Hello World!", link: "https://www.apple.com/")

output :

enter image description here

Sunil Targe
  • 7,251
  • 5
  • 49
  • 80
  • That's not answering OP's question. He would like to show other App's actions, such as WhatsApp, which is only possible to be shown in actual device. – Raptor Aug 22 '18 at 09:07
0

swift 4.2 That code working now

        let text = "race"
        let url = "https://medium.com/@javedmultani16/share-text-image-and-url-by-using-uiactivityviewcontroller-in-swift-4eb253e43d55"
        let shareAll = [text, url] as [Any]
        let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view
        self.present(activityViewController, animated: true, completion: nil)
Srinivasan_iOS
  • 972
  • 10
  • 12
  • Please put your answer always in context instead of just pasting code. See [here](https://stackoverflow.com/help/how-to-answer) for more details. – gehbiszumeis Apr 01 '19 at 05:32