1

iOS 5 のアプリ内から Twitter アプリを開こうとしていますが、開きません。以下に使用しているコードを含めました。

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

私を助けてください、そして前もって感謝します!

4

2 に答える 2

4

実際の Twitter アプリを開こうとしているだけの場合、コードは次のとおりです。

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://"]];
于 2012-04-04T05:52:59.470 に答える
0

Twitter アプリを起動しますか、それとも単にアプリ内からツイートを送信しますか? 上記のコードは、設定アプリでTwitterの設定を起動するためのものだと思います...これも5.1では許可されていないと思います

アプリに Twitter 統合を追加しようとしている場合、Apple は、iOS 5 に組み込まれている Twitter フレームワークで Twitter を使用する方法を示す優れたサンプル コードを提供しています。

ここで、このサンプル コードをダウンロードして、ツイートを送信するために他に何が必要か (CanTweetStatus の確認など) を確認することをお勧めしますが、ツイートを送信する方法の基本的なアイデアをこの投稿に添付します。

https://developer.apple.com/library/ios/#samplecode/Tweeting/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011191

- (IBAction)sendCustomTweet:(id)sender {
    // 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];

            // 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:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] 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]];
                    [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
                }];
            }
        }
    }];
}

幸運を!

于 2012-04-04T05:15:53.497 に答える