document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //
  2. //  TwitterHelloWorldViewController.m
  3. //  TwitterHelloWorld
  4. //
  5. //  Created by Kurry Tran on 10/17/11.
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "TwitterHelloWorldViewController.h"
  10.  
  11. @implementation TwitterHelloWorldViewController
  12. @synthesize _tweetSheet;
  13. - (void)didReceiveMemoryWarning
  14. {
  15.     [super didReceiveMemoryWarning];
  16.     // Release any cached data, images, etc that aren\'t in use.
  17. }
  18.  
  19. #pragma mark - View lifecycle
  20.  
  21.  
  22. /*
  23.  1. Check For Availability
  24.  
  25.  
  26.  */
  27.  
  28.  
  29. - (void)viewDidLoad
  30. {
  31.     [super viewDidLoad];
  32.     // Do any additional setup after loading the view, typically from a nib.
  33.     [self buildTweetSheet];
  34. }
  35.  
  36.  
  37.  
  38. - (void)buildTweetSheet{
  39.    
  40.     /* make instance of tweet sheet */
  41.     _tweetSheet = [[TWTweetComposeViewController alloc] init];
  42.    
  43.     //Specify the completion handler
  44.     TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result){
  45.         [self dismissModalViewControllerAnimated:YES];
  46.     };
  47.    
  48.     [_tweetSheet setCompletionHandler:completionHandler];
  49. }
  50.  
  51. +(BOOL)canSendTweet{
  52.    
  53.     BOOL _showTweetButton;
  54.     /* Checks For Service Availability */
  55.     if ([TWTweetComposeViewController canSendTweet] ) {
  56.         // show my tweet button
  57.         _showTweetButton = YES;
  58.     }
  59.    
  60.    
  61.     return _showTweetButton;
  62. }
  63.  
  64.  
  65. /* Sizing Notes
  66.  
  67.  - 140 characters maximum
  68.  - Images and URLs use characters
  69.     - currently uses 19 characters
  70.  - URL Lengths could change; use return BOOLs!
  71.  
  72.  */
  73.  
  74. /* This method sets the initial text of the tweet  */
  75. - (BOOL)setIntialText:(NSString *)text{
  76.    
  77.     BOOL allowed;
  78.    
  79.     // Try to set initial text
  80.     allowed = [_tweetSheet setInitialText:text];
  81.    
  82.     return allowed;
  83. }
  84.  
  85. /* Add Image To Image */
  86. -(BOOL)addImageToSheet:(UIImage *)image{
  87.    
  88.     BOOL allowed;
  89.    
  90.     // Try to add an image to the sheet
  91.     allowed = [_tweetSheet addImage:image];
  92.    
  93.     return allowed;
  94. }
  95.  
  96. /* Setup URL Shortening  */
  97.  
  98. - (BOOL)addURLToSheet:(NSURL *)url{
  99.    
  100.     NSString *stringURL = @"http://www.kurrytran.com";
  101.    
  102.     NSURL *newURL = [[NSURL alloc] initWithString:stringURL];
  103.    
  104.     BOOL allowed;
  105.    
  106.     /* Try to add a URL to sheet, returns NO
  107.      if unsuccessful. */
  108.    
  109.     allowed = [_tweetSheet addURL:newURL];
  110.    
  111.     return allowed;
  112. }
  113.  
  114. -(IBAction)presentTweetSheet:(id)sender{
  115.    
  116.     NSURL *url = [[NSURL alloc] initWithString:@"http://kurrytran.blogspot.com"];
  117.     [_tweetSheet addURL:url];
  118.    
  119.   // [_tweetSheet setInitialText:@"http://kurrytran.blogspot.com"];
  120.     // Show our tweet sheet
  121.     [self presentModalViewController:_tweetSheet animated:YES];
  122.    
  123.    
  124. }
  125.  
  126.  
  127.  
  128.  
  129. - (void)viewDidUnload
  130. {
  131.     [super viewDidUnload];
  132.     // Release any retained subviews of the main view.
  133.     // e.g. self.myOutlet = nil;
  134. }
  135.  
  136. - (void)viewWillAppear:(BOOL)animated
  137. {
  138.     [super viewWillAppear:animated];
  139. }
  140.  
  141. - (void)viewDidAppear:(BOOL)animated
  142. {
  143.     [super viewDidAppear:animated];
  144. }
  145.  
  146. - (void)viewWillDisappear:(BOOL)animated
  147. {
  148.     [super viewWillDisappear:animated];
  149. }
  150.  
  151. - (void)viewDidDisappear:(BOOL)animated
  152. {
  153.     [super viewDidDisappear:animated];
  154. }
  155.  
  156. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  157. {
  158.     // Return YES for supported orientations
  159.     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  160. }
  161.  
  162. @end
  163.  
  164.  
');