Use a weak link and some code as shown below:
- (void)tweet
{
Class tweeterClass = NSClassFromString(@"TWTweetComposeViewController");
if(tweeterClass != nil) {
if([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if(result == TWTweetComposeViewControllerResultDone) {
}
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:tweetViewController animated:YES completion:nil];
} else {
#if !(TARGET_IPHONE_SIMULATOR)
[self displayAlert:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup."];
#else
NSString *tweetString = [NSString stringWithFormat:@"http://mobile.twitter.com/home?status=%@%@", [self urlEncode:@"Check out this awesome pic: "] ,[self urlEncode:[_blobTweet.shortUrl absoluteString]]];
NSURL *tweetURL = [NSURL URLWithString:tweetString];
if ([[UIApplication sharedApplication] canOpenURL:tweetURL]) {
[[UIApplication sharedApplication] openURL:tweetURL];
}
#endif
}
} else {
}
}
@end
source
share