gpt4 book ai didi

iphone - TWTeetComposeViewController发布新推文后执行自定义代码

转载 作者:行者123 更新时间:2023-12-01 18:30:03 25 4
gpt4 key购买 nike

因此,使用iOS5中新的Twitter框架,我们可以使用以下简单代码轻松发布Twitter更新:

if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:@"Tweeting from Steamerduck :)"];
[controller presentModalViewController:tweetSheet animated:YES];
}

但是,我想在用户单击“发送到此处”后执行一些自定义代码:

在TWTweetComposeViewController发送一条推文之后,是否可以执行一些自定义代码和我自己的某些方法?

最佳答案

您可以指定一个完成处理程序,该处理程序在用户编写完该tweet之后被调用。看起来像这样(我还没有机会在设备上进行测试):

if ([TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:@"Tweeting from Steamerduck :)"];

// Set a completion handler to be called when the user is done
// composing their tweet

[tweetSheet setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultDone) {
// Tweet was sent, do something
} else if (result == TWTweetComposeViewControllerResultCancelled) {
// Do something else if the user cancelled

[controller dismissModalViewControllerAnimated:YES];
}
}];

[controller presentModalViewController:tweetSheet animated:YES];
}

关于iphone - TWTeetComposeViewController发布新推文后执行自定义代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10065040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com