我想從iOS 5中的應用程序中打開Twitter應用程序,但它不會打開。任何幫助將不勝感激,我已經包括我在下面使用的代碼。從我的iOS 5應用程序打開Twitter應用程序
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
請幫助我,並提前致謝!
我想從iOS 5中的應用程序中打開Twitter應用程序,但它不會打開。任何幫助將不勝感激,我已經包括我在下面使用的代碼。從我的iOS 5應用程序打開Twitter應用程序
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
請幫助我,並提前致謝!
你想推出Twitter應用程序,還是隻發送你的應用程序內的推文?我相信您上面顯示的代碼是在您的設置應用中啓動Twitters偏好設置......我也相信已被禁止使用5.1
如果您希望將Twitter集成添加到您的應用中Apple提供了很好的示例代碼向你展示如何在iOS 5中使用推特內置的Twitter框架使用Twitter。
現在我建議你下載這個示例代碼,看看還有什麼需要發送推文(如檢查CanTweetStatus),但我附加如何在這篇文章中發送推文的基本思路。
- (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];
}];
}
}
}];
}
祝您好運!
如果你只是試圖打開實際的Twitter的應用程序,然後將代碼
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://"]];
它打開Twitter的應用程序不是Twitter的設置。 – PJR 2012-07-04 08:20:32
不允許從應用程序打開偏好設置 – Otium 2012-07-04 21:02:25