2013-07-02 3 views
1

У меня проблема с прикрепленным кодеком. Он должен закрыть отображаемый в данный момент modalViewController когда пользователь нажмите раз на кнопку отмены вместо дважды, как это делают сейчас.SLComposeViewController cancel не закрывает VC одним нажатием

Код

- (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]; 
    } 

} 

ответ

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."); 
     }]; 
    }); 
};