私はTwitterの実装に不慣れです。私のアプリケーションには、ログイン画面が1つあります。また、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とそのドキュメントにアクセス (およびブックマーク) していないようです: