ShareKit modal view controller won't go away
Asked Answered
V

4

15

I'm using ShareKit 0.2.1 on Xcode 4.2 (iOS SDK 5) to share text on Twitter. It shares fine, but the modal view controller wont go away after successfully sharing on after clicking on the cancel button (see below):

enter image description here

And this is my code:

-(IBAction)shareOnTwitter:(id)sender{


    // Item to share
    NSString *text = @"Go away, modal view controller!";

    [SHKTwitter shareText:text];

}

What am I doing wrong?

Valera answered 30/10, 2011 at 2:42 Comment(0)
A
30

It is an iOS 5 issue. It's because ShareKit is using a method on UIViewController called parentViewController and according to the Apple docs you can no longer use this in iOS 5. Instead, you must use presentingViewController.

So to fix it in the ShareKit code, go into SHK.m, find the method with signature (void)hideCurrentViewControllerAnimated:(BOOL)animated, and replace it with:

- (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];
        } else if ([currentView presentingViewController] != nil) {
            self.isDismissingView = YES;
            [[currentView presentingViewController] dismissModalViewControllerAnimated:animated];
    } else
        self.currentView = nil;
    }
}

This works for me on iOS 5.

Arbela answered 31/10, 2011 at 20:22 Comment(2)
This is the solution I implemented as wellNone
y it is changing the orientation of deviceDichlorodifluoromethane
A
2
if (isDismissingView)
    return;

if (currentView != nil)
{
    // Dismiss the modal view
    if ([currentView parentViewController] != nil)
    {
        self.isDismissingView = YES;
        [[currentView parentViewController] dismissModalViewControllerAnimated:animated];
    }

    else {
        //## ADD BELOW ##
        self.isDismissingView = YES;
        [currentView dismissModalViewControllerAnimated:animated];
        self.currentView = nil;

    }
}
else {
    [[self getTopViewController].navigationController popViewControllerAnimated:YES];
}
Autophyte answered 12/2, 2012 at 15:28 Comment(0)
A
1

This is the code I use in one of my apps. It dismisses fine.

NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/packager/id459511278?l=nl&ls=1&mt=8"];
NSString *twittertext = [[NSString alloc] initWithFormat: @"Tweet Text"];
SHKItem *item = [SHKItem URL:url twittertext];

// Share the item
[SHKTwitter shareItem:item];
[twittertext release]; 
Actinouranium answered 30/10, 2011 at 10:43 Comment(1)
If you do [NSString stringWithFormat:@"Tweet Text"]; and remove the [twittertext release]; line, does it still dismiss? Apparently the only difference is that I'm using ARC...Valera
A
1

I have used the following code in my app (ARC disabled)

NSString *text = @"Go away, modal view controller!";

[SHKTwitter shareText:text];

I can confirm it dismisses fine. You probably changed some code in SHKTwitterForm.m when attempting to make Sharekit ARC compatible. Which resulted in your bug

Actinouranium answered 30/10, 2011 at 12:54 Comment(2)
Nope, I just compiled all the ShareKit files without ARC: -fno-objc-arcValera
I just reread your original question and found some confusion, How is it you're using Xcode 4.3 ? Also, what simulator version do you encounter the bug with? Did you test it on a real device as well?Actinouranium

© 2022 - 2024 — McMap. All rights reserved.