1

This question is a bit specific but I am going to ask it anyway. So I have properly followed all the instructions for ShareKit 2.0 installation from here: https://github.com/ShareKit/ShareKit/wiki/Installing-sharekit

Everything compiles fine and so-forth. The only file I have added to is the DefaultSHKConfigurator.m file with my information for the sharers.

So for example I call SHKMail like this:

SHKItem *item = [SHKItem image:image title:@"Hey"];
        [item setText:myText];
        [item setURL:appURL];
        if ([SHKMail canShare]) {
            [SHKMail shareItem:item];
        }

The first time it loads fine no issues, and closes fine. The second time I execute this code nothing happens on the device. This issue is not constrained to SHKMail, it happens will ALL the sharers. I have narrowed down the issue to the SHK.m class.

In the showViewController method, this code gets called the second time around:

// If a view is already being shown, hide it, and then try again
    if (currentView != nil)
    {
        self.pendingView = vc;
        [[currentView parentViewController] dismissModalViewControllerAnimated:YES];
        return;
    }

That code should not get called the second time I execute the first code snippet I posted. Anyway, what could be causing this? What else could I try to debug? Any ideas?

I think that anyone who helps me fully fix this issue, will get a 50 point bounty.

Thanks for anyone who attempts to answer this! :)

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

3 Answers3

0

This is a shot in the dark but I've pulled my hair out over share kit problem before so I know anything is helpful.

It seems that after the view is dismissed the first time the currentView never gets set to nil.

I see that they have updated some of the methods to work with iOS 5. Try changing this in SHK.m

- (void)hideCurrentViewControllerAnimated:(BOOL)animated
{
    if (isDismissingView)
        return;

    if (currentView != nil)
    {
        // Dismiss the modal view
        if ([currentView parentViewController] != nil)
        {
            self.isDismissingView = YES;
            [[currentView parentViewController] dismissModalViewControllerAnimated:animated];
        }
        // for iOS5
        else if([currentView respondsToSelector:@selector(presentingViewController)] &&
                [currentView presentingViewController])
        {
            self.isDismissingView = YES;            
            [[currentView presentingViewController] dismissViewControllerAnimated:animated completion:^{                                                                           
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    [[NSNotificationCenter defaultCenter] postNotificationName:SHKHideCurrentViewFinishedNotification object:nil];

                     //THIS IS NEW
                     self.currentView = nil;
                }];
            }];
        }

        else
            self.currentView = nil;
    }
}

I only added in a forced self.currentView = nil; call after the view has been dismissed in iOS5.

random
  • 8,568
  • 12
  • 50
  • 85
  • Thanks for the attempt but unfortunately this causes the app to crash when dismissing the sharer the second time around. Any other thoughts? – SimplyKiwi Aug 15 '12 at 22:52
  • This could also pertain to K S answer but are you running into this problem on the simulator? – random Aug 16 '12 at 00:34
  • I can't test on the Simulator due to the fact I use some device only code in many places. – SimplyKiwi Aug 16 '12 at 00:50
0

I am also using ShareKit 2.0 for Facebook sharing (i.e. [SHKFacebook shareItem:item]), and have not encountered the problem you are currently facing.

I have tested your code (i.e. [SHKMail shareItem:item]) in iPhone Simulator 4.3 and 5.1 without any issues.

It could be your environment wasn't set up correctly or your code wasn't up-to-date.

K S
  • 212
  • 1
  • 1
  • My code is absolutely up to date. What exactly in the environment could be causing this issue? – SimplyKiwi Aug 16 '12 at 00:17
  • Hi iBrad, I am not sure what was causing your issue. Can you simplify your app (or create a test app) to see if the problem is reproducible. – K S Aug 16 '12 at 23:10
  • I can make a test app. Give me a few days and I'll post the link to it here. Are you willing to go through that project and see what's wrong though? I'll give you a 50 point bounty, an up vote, and I'll accept your answer since your new to this site but only if you help me fix this issue fully :) – SimplyKiwi Aug 17 '12 at 03:45
  • No problem at all, as I am also learning how to use it. However, if you are only interested in sending emails, it would be better to use the built-in MFMailComposeViewController, as it would reduce your footprint and dependencies. – K S Aug 18 '12 at 06:32
  • Okay thanks. I am in fact using Facebook, Twitter, SMS, and E-Mail. Just give me a few days and I'll have the project ready. – SimplyKiwi Aug 18 '12 at 06:35
0

I have managed to successfully fix this issue by looking at this question also on StackOverflow: I ended up fixing this issue by this answer: ShareKit method swizzling in Lion / Xcode 4.3.1?

Pretty much just stay away from method swizzling.

Community
  • 1
  • 1
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191