iphone - 从 ACAccountStore 打开 Twitter 设置 (iOS 5.1 TWITTER)

标签 iphone objective-c ios5 twitter ios5.1

在 iOS 5.0 中,我通过

从我的应用程序中打开 Twitter 设置

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

但是,此功能在 iOS 5.1 中被删除,因此我无法打开 twitter 设置。

现在我在用

 + (void)makeRequestsWithURL: (NSURL *)url {
// 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];
[self canTweetStatus];

// 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];

        // For the sake of brevity, we'll assume there is only one Twitter account present.
        // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
        if ([accountsArray count] > 0) {
            // Grab the initial Twitter account to tweet from.
            ACAccount *twitterAccount = [accountsArray objectAtIndex:0];


            // Create a request, which in this example, posts a tweet to the user's timeline.
            // This example uses version 1 of the Twitter API.
            // This may need to be changed to whichever version is currently appropriate.
            TWRequest *postRequest = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodPOST];

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

            // Perform the request created above and create a handler block to handle the response.
            [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                iOS5Twitter *twitter5 = [[iOS5Twitter alloc] init];
                [twitter5 performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
                [twitter5 release];                }];
        }
    }

}];

为了发出请求,我可以通过

检查我是否登录了

if ([TWTweetComposeViewController canSendTweet])

但现在我想:如果我没有登录,它将显示如图所示的警报,并想转到 Twitter 设置。是否可以 ?或者我必须手动去 ti twitter 设置? enter image description here

最佳答案

这有点棘手,我通过删除 *TWTWeetComposeViewController* 中的 subview 来实现,因此它仅在用户未登录时显示警报,通过单击设置按钮,我们可以打开设置我的应用中的页面。

     + (void)setAlertForSettingPage :(id)delegate 
    {
     // Set up the built-in twitter composition view controller.
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];


        // Create the completion handler block.
        [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [delegate dismissModalViewControllerAnimated:YES];
        }];

        // Present the tweet composition view controller modally.
        [delegate presentModalViewController:tweetViewController animated:YES];
        //tweetViewController.view.hidden = YES;
        for (UIView *view in tweetViewController.view.subviews){
            [view removeFromSuperview];
        }

     } 

这里,deleate 是你的 viewcontroller,如果你在你的 viewcontroller 中使用这个方法,只需使用 self 而不是 delegate

关于iphone - 从 ACAccountStore 打开 Twitter 设置 (iOS 5.1 TWITTER),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11325266/

相关文章:

ios - 无法按下具有拐角半径的 UIView 下方的 UIButton

ios5 - 错误 :(null) is not a valid containment controller key path?

iphone - 标签栏 Controller 应用程序中没有顶部导航栏

ios - 在 xcode 中处理不同的屏幕尺寸

objective-c - self 管理/释放对象在 Xcode -> 产品 -> 分析下报告为 "Potential leak of object"

iphone - Ios加密。?

iphone - NSCheckingResult 范围属性未设置为 {NSNotfound,0}?

iphone - 应用程序仍在后台运行 Xcode 4.2 iOS 5

iphone - 根据两个图像之间的差异创建蒙版 (iPhone)

iphone - 您的 Apple ID 已被禁用 [环境 : Sandbox]