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

PJR*_*PJR 7 iphone twitter objective-c ios5 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];                }];
        }
    }

}];
Run Code Online (Sandbox Code Playgroud)

}

为了提出要求,我能够检查我是否被淹没了

if ([TWTweetComposeViewController canSendTweet])

但现在我想要:如果我没有插入它会显示如图所示的警报并想要转到推特设置.可能吗 ?或者我必须手动去推特设置?在此输入图像描述

PJR*_*PJR 17

这有点棘手,我通过删除子视图得到*TWTWeetComposeViewController*,所以它只显示当用户没有进入时的警报,并通过点击设置按钮,我们可以在我的应用程序中打开设置页面.

     + (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];
        }

     } 
Run Code Online (Sandbox Code Playgroud)

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


Sen*_*ior 8

iOS 6使用SLComposeViewController而不是TWTweetComposeViewController,所以如果你想让它在iOS 6和iOS 5上运行,你必须这样做:

    UIViewController *tweetComposer;

    if([SLComposeViewController class] != nil)
    {
        tweetComposer = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        [(SLComposeViewController *)tweetComposer setCompletionHandler:^(SLComposeViewControllerResult result)
         {
            // do whatever you want
         }];
    }
    else
    {
        tweetComposer = [[TWTweetComposeViewController alloc] init];

        [(TWTweetComposeViewController *)tweetComposer setCompletionHandler:^(TWTweetComposeViewControllerResult result)
         {
            // do whatever you want
         }];
    }

    for (UIView *view in [[tweetComposer view] subviews])
        [view removeFromSuperview];

    [self presentViewController:tweetComposer animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)

  • 与黑色阴影有同样的问题 - 呈现的UIViewController的遗体,我假设.通过替换//上面的两个出现来解决这个问题[自我解除ViewControllerAnimated:NO completion:nil]; 现在它工作正常. (2认同)