gpt4 book ai didi

ios - 我如何在不显示 ios 对话的情况下在 Twitter 上发帖?

转载 作者:行者123 更新时间:2023-11-28 22:06:09 24 4
gpt4 key购买 nike

我想在 Twitter 上发布我的状态。我想添加图片,但不想分享对话。

相反,我想要一个像 Instagram 这样的界面,用户只需选择 Twitter 并按下“分享”,这样就很简单了。

到目前为止,这是我的运行代码:

//  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 required 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;
}
};

// Set the initial body of the Tweet
[tweetSheet setInitialText:@"Socia"];

// 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:@"icon120x120.png"]]) {
NSLog(@"Unable to add the image!");
}

// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com/questions/ask?title="]]){
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.");
}];

最佳答案

 [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
//use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

//create this request
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://api.twitter.com"@"/1.1/statuses/update_with_media.json"] parameters: [NSDictionary dictionaryWithObject:message forKey:@"status"]];
UIImage *imageToPost = [UIImage imageNamed:@"image.jpg"];
NSData *imageData = UIImageJPEGRepresentation(imageToPost, 1.0f);//set the compression quality
[postRequest addMultipartData:imageData withName:@"media" type:@"image/jpeg" filename:@"image.jpg"];

//set account and same as above code

....
....

以上来自这个link这段代码对我有用。

在这里您可以找到如何使用媒体发布 Twitter 更新 here .

关于ios - 我如何在不显示 ios 对话的情况下在 Twitter 上发帖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23912592/

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