Это пример приложения для Твиттера, которое я сделал после учебника на сайте разработчиков Apple.Но я не знаю, что я сделал неправильно, чтобы это произошло.
Интерфейс:
@interface TWTViewController : UIViewController {
NSString* output;
}
@property (nonatomic, copy) NSString* output;
- (IBAction)doTweet:(id)sender;
- (IBAction)getTimeline:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *outputLabel;
@property (weak, nonatomic) IBOutlet UIButton *tweetButton;
@end
Реализация:
@implementation TWTViewController
@synthesize output = _output;
@synthesize outputLabel;
@synthesize tweetButton;
...
- (IBAction)doTweet:(id)sender {
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"It's really that simple!"];
[twitter addImage:[UIImage imageNamed:@"twitter.png"]];
[self presentViewController:twitter animated:YES completion:nil];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if(res == TWTweetComposeViewControllerResultDone) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your Tweet was posted succesfully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else if(res == TWTweetComposeViewControllerResultCancelled) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your Tweet was not posted." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
[self dismissModalViewControllerAnimated:YES];
};
}
- (IBAction)getTimeline:(id)sender {
ACAccountStore* store = [[ACAccountStore alloc] init];
ACAccountType* twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
NSArray* twitterAccounts = [store accountsWithAccountType:twitterAccountType];
if([twitterAccounts count] > 0) {
ACAccount* account = [twitterAccounts objectAtIndex:0];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"1" forKey:@"include_entities"];
NSURL* url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
TWRequest* request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if(error != nil) {
self.output = [error localizedDescription];
self.outputLabel.text = self.output;
}
else {
NSError* jsonError;
NSArray* timeline = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&jsonError];
if(jsonError == nil) {
self.output = [timeline componentsJoinedByString:@"|"];
self.outputLabel.text = self.output;
}
else {
self.output = [jsonError localizedDescription];
self.outputLabel.text = self.output;
}
}
}];
}
}
}];
}
@end
Вот ZIP-файл, содержащий всеПроект: http://www.mediafire.com/?yi4x3d6qn1x4p4r
Любая помощь будет принята с благодарностью.