1

我对附加的代码有疑问。当用户点击取消按钮一次而不是像现在这样两次时,它必须关闭当前显示的 modalViewController 。

代码

- (BOOL)isIOS6 {
    BOOL native = YES;
    if([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0f){
        native = NO;
    }
    return  native;
}

- (void)twitterShare {
    DLog(@"is ios6: %d", [self isIOS6]);

    if ([self isIOS6]) {

        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
        {
            NSString *textToShare = @"Test";
            SLComposeViewController *twitterComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
            twitterComposeViewController.completionHandler = ^(SLComposeViewControllerResult result){
                DLog(@"result: %d", result);

                if (result == 1) {
                    Dlog(@"Shared");
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"notitificationName" object:nil];
                    DLog(@"Sended provide bonus notification");
                    [self disableButtonWithTag:GrowthButtonTwitterConnectTag];
                    DLog(@"disable that button.");
                } else {
                    Dlog(@"canceled...");
                }
            };

            [twitterComposeViewController setInitialText:textToShare];
            [self presentViewController:twitterComposeViewController animated:YES completion:nil];

        } else {
            DLog(@"Twitter not available");
        }

    } else {
        // iOS 5 not supported message
        [[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ATTENTION", nil)
                                     message:NSLocalizedString(@"IOS6_OR_ABOVE_FEATURE", nil)
                                    delegate:nil
                           cancelButtonTitle:NSLocalizedString(@"OK", nil)
                           otherButtonTitles:nil, nil] autorelease] show];
    }

}
4

1 回答 1

1

我已经设法用以下代码解决了这个问题:

tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
    switch(result) {
            //  This means the user cancelled without sending the Tweet
        case SLComposeViewControllerResultCancelled:
            break;
            //  This means the user hit 'Send'
        case SLComposeViewControllerResultDone:
            [[NSNotificationCenter defaultCenter] postNotificationName:@"kGrowthProvideTwitterBonus" object:nil];
            DLog(@"Sended provide bonus notification");
            [self disableButtonWithTag:TTGrowthButtonTwitterConnectTag];
        break;
    }

    //  dismiss the Tweet Sheet
    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:NO completion:^{
            NSLog(@"Tweet Sheet has been dismissed.");
        }]; 
    });
};
于 2013-07-02T14:48:10.190 回答