我是 twitter 实现的新手,在我的应用程序中有一个登录屏幕,我还想提供一个 twitter 登录选项,这意味着用户也可以从他的 twitter 帐户登录。
请提供一些有用的提示,如何做到这一点。
您可以使用 TwitterShare 文件。
TwitterShare.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
@interface TwitterShare : UIViewController
{
TWTweetComposeViewController *_tweetSheet;
}
@property (nonatomic, retain) TWTweetComposeViewController *_tweetSheet;
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow;
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView*) viewOnWhichToShow;
@end
TwitterShare.m
#import <MobileCoreServices/UTCoreTypes.h>
#import "TwitterShare.h"
#import "ProgressIndicator.h"
@implementation TwitterShare
@synthesize _tweetSheet;
#pragma mark -
#pragma mark View methods
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
#pragma mark -
#pragma mark Showing Tweet Sheet
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow
{
/* make instance of tweet sheet */
_tweetSheet = [[TWTweetComposeViewController alloc] init];
/* Specify the completion handler */
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result)
{
[self dismissModalViewControllerAnimated:YES];
NSString *info;
if(result == TWTweetComposeViewControllerResultDone)
{
info = [NSString stringWithFormat:@"Saved"];
ProgressIndicator *indicator = [[ProgressIndicator alloc]init];
[indicator tweetSuccessOrFail:info view:viewOnWhichToShow];
[indicator release];
indicator = nil;
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
// statements if tweet sheet cancelled.
}
[_tweetSheet release];
_tweetSheet = nil;
};
[_tweetSheet setCompletionHandler:completionHandler];
}
#pragma mark -
#pragma mark Share to Twitter
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView *)viewOnWhichToShow
{
[self setView:viewOnWhichToShow];
[self buildTweetSheet:viewOnWhichToShow];
/* add Image To _tweetSheet */
/* Show our tweet sheet */
[_tweetSheet addImage:imageToUpload];
[self presentModalViewController:_tweetSheet animated:YES ];
}
看起来你还没有访问(和收藏)Twitter Developers及其文档: