3

I'm using ShareKit to share objects to Twitter, Facebook, and Email. Twitter and Facebook works fine, but email doesn't. And I don't really know why.

It seems like it works quite randomly.

I set it up like this:

[self.customView.shareButton addTarget:self action:@selector(sharePost:) forControlEvents:UIControlEventTouchUpInside];

- (void)sharePost:(UIButton *)sender
{
    NSURL *url = [NSURL URLWithString:self.currentPost.link];

    // Add image.
    NSString *imageUrlString = [NSString stringWithFormat:[link]];
    NSURL *imageUrl = [NSURL URLWithString:imageUrlString];
    UIImageView *postImage = [[UIImageView alloc] init];
    [postImage setImageWithURL:imageUrl];

    SHKItem *item = [SHKItem image:postImage.image title:[NSString stringWithFormat:@"%@", self.currentPost.title]];
    [item setURL:url];
    [item setMailBody:[NSString stringWithFormat:@"%@ %@", self.currentPost.title, self.currentPost.link]];

    // Get the ShareKit action sheet
    // This works
    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

    // ShareKit detects top view controller (the one intended to present ShareKit UI) automatically,
    // but sometimes it may not find one. To be safe, set it explicitly.
    [SHK setRootViewController:self];

    // Display the action sheet.
    [actionSheet showInView:self.view];
}

Any ideas or what I'm missing or doing wrong?

Anders
  • 2,903
  • 7
  • 58
  • 114
  • I was having a similar problem, but then I found this answer (http://stackoverflow.com/questions/7240720/mail-sharing-option-not-visible) which basically says e-mail won't work in the simulator since e-mail can't be set up in the simulator. Are you working on the simulator only? Or on a device where e-mail has not been configured? – Bryan Hanson Aug 23 '12 at 15:50
  • Hi, I have tested on both. The problem isn't with sending but with displaying the actionsheet. It dosn't show every time, which I find quite strange. – Anders Aug 23 '12 at 19:14
  • Ah, I see. I wasn't sure what you meant by it 'works quite randomly'. So the action sheet shows up, but the send e-mail button is intermittent, or is the whole answer sheet intermittent? – Bryan Hanson Aug 23 '12 at 20:54
  • The whole answer sheet is intermittent. – Anders Aug 23 '12 at 22:31
  • Well, this may be off the mark, but I have a button that is hardwired like this `- (IBAction) shareApp:(id)sender` which contains code similar (but simpler) than what you have in your `sharePost`. Maybe you the `@selector` approach you are using is not communicating cleanly. But maybe you aren't using a nib so you can't use `IBAction`? – Bryan Hanson Aug 23 '12 at 22:53
  • Thanks, I probably was unclear again. I get the "menu bar" to show up, with the email, Facebook and twitter button. But when I click on email there, the send form doesn't always display. – Anders Aug 24 '12 at 06:56
  • Then try removing as much as you can from your code above which customizes things, get down to bare bones. That way you can figure out if it is your code somehow, or a problem with SHK. Look at the SHK example project for the minimum required. See if it works. Then build it back up one step at a time. Good Luck! – Bryan Hanson Aug 24 '12 at 10:41
  • What ShareKit version are you using? You should use the latest ShareKit from here: https://github.com/ShareKit/ShareKit – SimplyKiwi Aug 28 '12 at 00:27

1 Answers1

1

Try to change the RootViewController and view you are using:

[SHK setRootViewController:self.view.window.rootViewController];
[actionSheet showInView:self.view.window.rootViewController.view];

Most likely your view controller hierarchy is somewhat messed up.

Resh32
  • 6,500
  • 3
  • 32
  • 40