gpt4 book ai didi

ios - 如何通过隐藏 SLComposeViewController *tweetSheettweet 实例在 Twitter 上发帖

转载 作者:可可西里 更新时间:2023-11-01 17:08:34 24 4
gpt4 key购买 nike

我的应用需要支持 iOS 5。

我有我的自定义 UI,用户可以在其中输入推文消息,当他按下发布按钮时,它应该发布消息推特。

我已经编写了通过 SLComposeViewController *tweetSheet 实例发布的代码但在这种情况下,我不能直接按下 tweetSheet 提供的发送按钮,而无需通过

[self presentViewController:tweetSheet animated:YES completion:nil];

是否可以绕过此演示文稿并设置文本消息并通过具有发布按钮的自定义用户界面发布到 Twitter??

  if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];


tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
switch(result) {
// This means the user cancelled without sending the Tweet
case SLComposeViewControllerResultCancelled:
NSLog(@"Tweet message was cancelled");
break;
// This means the user hit 'Send'
case SLComposeViewControllerResultDone:
NSLog(@"Done pressed successfully");
break;
}

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

[tweetSheet setInitialText:self.textViewPostedText.text];

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

如果用户有多个 Twitter 帐户,如何提供选择选项???

最佳答案

 - (IBAction)doneButtonClicked:(id)sender
{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSString *message = _textView.text;
//hear before posting u can allow user to select the account
NSArray *arrayOfAccons = [account accountsWithAccountType:accountType];
for(ACAccount *acc in arrayOfAccons)
{
NSLog(@"%@",acc.username); //in this u can get all accounts user names provide some UI for user to select,such as UITableview
}
in below


// Request access from the user to access their Twitter account
[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]; //hear this line replace with selected account. than post it :)

//Build a twitter request
TWRequest *postRequest = [[TWRequest alloc] initWithURL:
[NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"]
parameters:[NSDictionary dictionaryWithObject:message forKey:@"status"] requestMethod:TWRequestMethodPOST];//for iOS 7


//for iOS 6 use "https://api.twitter.com/1/statuses/update.json"
//Post the request
//u should get the response code 200 for successful post
[postRequest setAccount:acct];

//manage the response
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if(error)
{
//if there is an error while posting the tweet
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Error in posting" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
// on successful posting the tweet
NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Successfully posted" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}
}];
[postRequest release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"You have no twitter account" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
else
{
//suppose user not set any of the accounts
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Permission not granted" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
} ];

[account release]; //for non-ARC
}


关于ios - 如何通过隐藏 SLComposeViewController *tweetSheettweet 实例在 Twitter 上发帖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18459252/

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