我如何在推特上发布而不在ios中显示对话?
我想在twitter上发布我的状态。我想添加一个图像,但我不想共享对话 相反,我想要一个像Instagram这样的界面,用户只需选择twitter并按下“共享”,这样就很容易了 以下是我目前运行的代码:我如何在推特上发布而不在ios中显示对话?,ios,twitter,slcomposeviewcontroller,Ios,Twitter,Slcomposeviewcontroller,我想在twitter上发布我的状态。我想添加一个图像,但我不想共享对话 相反,我想要一个像Instagram这样的界面,用户只需选择twitter并按下“共享”,这样就很容易了 以下是我目前运行的代码: // Create an instance of the Tweet Sheet SLComposeViewController *tweetSheet = [SLComposeViewController comp
// 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.");
}];
以上就是这个代码,这个代码为我工作
在这里你可以找到如何用媒体发布Twitter的更新 这几乎应该是一个评论,而不是一个答案。当SO链接或twitter链接停止工作时会发生什么?这是真的!但我还不能发表评论:)下次再发一些代码。这样,如果这些链接确实过期,人们仍然有一个引用。@MartinoBonfiglioli在实现此代码警报后,显示已成功发布,当我看到我的帐户上没有任何内容,并在我看到nslog“Twitter响应,HTTP响应:400”时给我一个错误。请告诉我如何处理此问题?可能是重复的
[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
....
....