我想在用户通过 iOS6 的内置“推文表”发布推文后触发特定操作
我想在用户点击其“发送”按钮后触发一个方法。
或者,如果我可以从 iOS 收到一些确认推文已成功发布,我想触发该方法。
这些选项中的任何一个都可能吗?在用户发布推文后,是否有不同的首选方式来触发操作?
我想在用户通过 iOS6 的内置“推文表”发布推文后触发特定操作
我想在用户点击其“发送”按钮后触发一个方法。
或者,如果我可以从 iOS 收到一些确认推文已成功发布,我想触发该方法。
这些选项中的任何一个都可能吗?在用户发布推文后,是否有不同的首选方式来触发操作?
-(void)shareViewTwitter:(NSString*)str
{
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
// Optional: set an image, url and initial text
[twitter setInitialText:@"Some Text"];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed (Here your Action will be triggered)
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = @"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
// Your Action
msg = @"Tweet compostion was canceled.";
else msg = @"Tweet composition completed."; // Your Action
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}
使用完成处理程序。请参阅下面的代码示例。
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
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:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:NO completion:^{
NSLog(@"Tweet Sheet has been dismissed.");
}];
});
};