iOS 5 Twitter框架:无需用户输入和确认(模态视图控制器) [英] iOS 5 Twitter Framework: Tweeting without user input and confirmation (modal view controller)

查看:76
本文介绍了iOS 5 Twitter框架:无需用户输入和确认(模态视图控制器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想要的是应用程序,一旦用户允许访问他们的Twitter帐户,能够鸣叫用户在 UITableView 中选择的任何内容。理想情况下,我想在iOS 5中使用Twitter框架,但我所遇到的主要问题是模态视图控制器的tweeting。这是可选的吗?

Essentially what I want is for the app, once the user has allowed access to their Twitter account, to be able to tweet whatever the user has selected in a UITableView. Ideally I'd like to use the Twitter framework in iOS 5, but the main issue I'm having is the modal view controller for tweeting. Is this optional? Is it possible to tweet without it and if not, what do you suggest I do?

谢谢!

推荐答案

这是绝对可能的tweet没有它,以下是在生产的iOS 5应用程序。

It's definitely possible to tweet without it, the following is in production iOS 5 apps. It even takes the user to the requisite section of preferences if they haven't registered an account.

- (void)postToTwitter
{
    // Create an account store object.
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    // Create an account type that ensures Twitter accounts are retrieved.
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    // Request access from the user to use their Twitter accounts.
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if(granted) {
            // Get the list of Twitter accounts.
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];


            if ([accountsArray count] > 0) {
                // Grab the initial Twitter account to tweet from.
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
                TWRequest *postRequest = nil;

                postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:[self stringToPost] forKey:@"status"] requestMethod:TWRequestMethodPOST];



                // Set the account used to post the tweet.
                [postRequest setAccount:twitterAccount];

                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                        dispatch_async(dispatch_get_main_queue(), ^(void) {
                            if ([urlResponse statusCode] == 200) {
                                Alert(0, nil, @"Tweet Successful", @"Ok", nil);
                            }else {

                                Alert(0, nil, @"Tweet failed", @"Ok", nil);
                            }
                        });
                    }];
                });

            }
            else
            {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
            }
        }
    }];
}

这篇关于iOS 5 Twitter框架:无需用户输入和确认(模态视图控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆