iOS: How to share text and image on social networks?

♀尐吖头ヾ 提交于 2019-11-26 04:47:59

问题


Please, can you tell me if I\'m doing mistakes?

NSString *sharedMsg=[NSString stringWithFormat:@\"Hello world\"];
UIImage* sharedImg=[UIImage imageNamed:@\"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];

At runtime when I select the icon of Facebook the text is missing, the image is correctly displayed.
My xcode is 6.3.1, tested on iPad.


回答1:


It seems that a recent update to the Facebook application has replaced the in-built Facebook share activity with one that ignores status text - If you remove the Facebook app from your device the text will be displayed using the code you have. If you have the Facebook app installed you get images, URLs but not the text

Facebook's policies don't allow you to pre-populate status messages and require all content to be user generated - while I understand the intention behind this, I personally think it is kind of stupid in many cases - For example in my game I want to pre-populate the user's score, but now I can't, so the user is presented with an empty dialog box. I will probably simply remove the Facebook sharing option as no-one will ever use it now.

This response from Facebook confirms that the behaviour is by design




回答2:


Here is the answer in Swift. It may not help your problem, but it might be helpful with someone looking for this title. Just create a button and it's action. And install the button's action like this.

Note: You have to log in your facebook or twitter by going to setting. Then do like this.

@IBAction func onShareTouched(sender: AnyObject) {

    print("share")

    let myShare = "My beautiful photo! <3 <3"
    let image: UIImage = UIImage(named: "yourImageNameHere")

    let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [(image), myShare], applicationActivities: nil)
    self.presentViewController(shareVC, animated: true, completion: nil)

  }



回答3:


NSString* text=@"Hello world";
NSURL *myWebsite = [NSURL URLWithString:@"http://www.website.com/"];
//  UIImage * myImage =[UIImage imageNamed:@"myImage.png"];
NSArray* sharedObjects=@[text,myWebsite];
UIActivityViewController * activityViewController=[[UIActivityViewController alloc]initWithActivityItems:sharedObjects applicationActivities:nil];

activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];


来源:https://stackoverflow.com/questions/29890747/ios-how-to-share-text-and-image-on-social-networks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!