gpt4 book ai didi

objective-c - SLComposeViewController 完成处理程序

转载 作者:IT王子 更新时间:2023-10-29 08:07:51 26 4
gpt4 key购买 nike

您好,如果使用 SLComposeViewController CompletionHandler 完成推文,我如何收到通知。这是发送推文的代码

  if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Tweeting from my own app! :)"];
[tweetSheet addURL:[NSURL URLWithString:@"www.someurl.com"]];

[self presentViewController:tweetSheet animated:YES completion:NULL];
}

最佳答案

找到答案

- (void)showTweetSheet
{
// Create an instance of the Tweet Sheet
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:
SLServiceTypeTwitter];

// Sets the completion handler. Note that we don't know which thread the
// block will be called on, so we need to ensure that any UI updates occur
// on the main queue
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;
}

// dismiss the Tweet Sheet
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:NO completion:^{
NSLog(@"Tweet Sheet has been dismissed.");
}];
});
};

// Set the initial body of the Tweet
[tweetSheet setInitialText:@"just setting up my twttr"];

// Adds an image to the Tweet. For demo purposes, assume we have an
// image named 'larry.png' that we wish to attach
if (![tweetSheet addImage:[UIImage imageNamed:@"larry.png"]]) {
NSLog(@"Unable to add the image!");
}

// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
NSLog(@"Unable to add the URL!");
}

// Presents the Tweet Sheet to the user
[self presentViewController:tweetSheet animated:NO completion:^{
NSLog(@"Tweet sheet has been presented.");
}];
}

关于objective-c - SLComposeViewController 完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13428304/

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