//
// TwitterHelloWorldViewController.m
// TwitterHelloWorld
//
// Created by Kurry Tran on 10/17/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "TwitterHelloWorldViewController.h"
@implementation TwitterHelloWorldViewController
@synthesize _tweetSheet;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren\'t in use.
}
#pragma mark - View lifecycle
/*
1. Check For Availability
*/
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self buildTweetSheet];
}
- (void)buildTweetSheet{
/* make instance of tweet sheet */
_tweetSheet = [[TWTweetComposeViewController alloc] init];
//Specify the completion handler
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result){
[self dismissModalViewControllerAnimated:YES];
};
[_tweetSheet setCompletionHandler:completionHandler];
}
+(BOOL)canSendTweet{
BOOL _showTweetButton;
/* Checks For Service Availability */
if ([TWTweetComposeViewController canSendTweet] ) {
// show my tweet button
_showTweetButton = YES;
}
return _showTweetButton;
}
/* Sizing Notes
- 140 characters maximum
- Images and URLs use characters
- currently uses 19 characters
- URL Lengths could change; use return BOOLs!
*/
/* This method sets the initial text of the tweet */
- (BOOL)setIntialText:(NSString *)text{
BOOL allowed;
// Try to set initial text
allowed = [_tweetSheet setInitialText:text];
return allowed;
}
/* Add Image To Image */
-(BOOL)addImageToSheet:(UIImage *)image{
BOOL allowed;
// Try to add an image to the sheet
allowed = [_tweetSheet addImage:image];
return allowed;
}
/* Setup URL Shortening */
- (BOOL)addURLToSheet:(NSURL *)url{
NSString *stringURL = @"http://www.kurrytran.com";
NSURL *newURL = [[NSURL alloc] initWithString:stringURL];
BOOL allowed;
/* Try to add a URL to sheet, returns NO
if unsuccessful. */
allowed = [_tweetSheet addURL:newURL];
return allowed;
}
-(IBAction)presentTweetSheet:(id)sender{
NSURL *url = [[NSURL alloc] initWithString:@"http://kurrytran.blogspot.com"];
[_tweetSheet addURL:url];
// [_tweetSheet setInitialText:@"http://kurrytran.blogspot.com"];
// Show our tweet sheet
[self presentModalViewController:_tweetSheet animated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (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 != UIInterfaceOrientationPortraitUpsideDown);
}
@end