Guest User

Untitled

a guest
Aug 9th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. id HUD;
  2.  
  3. - (void)viewWillAppear:(BOOL)animated
  4. {
  5. [username becomeFirstResponder];
  6.  
  7. self.title = @"New User";
  8.  
  9. [[[self.navigationController viewControllers] objectAtIndex:0] hideError];
  10.  
  11. }
  12.  
  13. - (CGSize)contentSizeForViewInPopover
  14. {
  15. return CGSizeMake(400.0, 400.0);
  16. }
  17.  
  18. - (IBAction)addAccount:(id)sender{
  19. engine = [[MGTwitterEngine alloc] initWithDelegate:self];
  20. [engine setUsesSecureConnection:YES];
  21. [engine setConsumerKey:@"vobfhfyZPjkKufUFS235Hg"
  22. secret:@"hnabIs54MXaJZbtA6yACn8bVUkm9jeyrkcnrU7jRi4"];
  23. [engine getXAuthAccessTokenForUsername:username.text password:password.text];
  24. [password resignFirstResponder];
  25. [username resignFirstResponder];
  26. HUD = [[UIProgressHUD alloc] initWithFrame:CGRectMake((self.view.bounds.size.width/2)-100, (self.view.bounds.size.height/2)-60, 200, 120)];
  27. [self.view addSubview:HUD];
  28. [HUD setText:@"Authorizing"];
  29. [HUD show:YES];
  30. }
  31.  
  32. #pragma mark MGTwitterEngineDelegate methods
  33.  
  34.  
  35. - (void)requestSucceeded:(NSString *)connectionIdentifier
  36. {
  37. NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
  38. }
  39.  
  40. - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
  41. {
  42. NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
  43. connectionIdentifier,
  44. [error localizedDescription],
  45. [error userInfo]);
  46.  
  47. [HUD setText:@"Error"];
  48. [HUD setNeedsDisplay];
  49. [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
  50. }
  51.  
  52. - (void)accessTokenReceived:(OAToken *)aToken forRequest:(NSString *)connectionIdentifier {
  53.  
  54. token = aToken;
  55. [engine setAccessToken:token];
  56.  
  57. [HUD setText:@"Validated"];
  58. [HUD done];
  59. [HUD setNeedsDisplay];
  60. [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
  61.  
  62. NSDictionary *accountInfo = [[NSDictionary alloc] initWithObjectsAndKeys: username.text, @"username", password.text, @"password",nil];
  63. [[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"AccountsArray"] addObject:accountInfo];
  64.  
  65. NSLog(@"%@", [[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"]);
  66. [[[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"] writeToFile:@"/Users/Mac/Desktop/Test.txt" atomically:YES];
  67.  
  68. [[NSUserDefaults standardUserDefaults] setObject:username.text forKey:@"username"];
  69. [[NSUserDefaults standardUserDefaults] setObject:password.text forKey:@"password"];
  70. [[NSUserDefaults standardUserDefaults] synchronize];
  71.  
  72. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TwitFirstLaunch"];
  73.  
  74. [[NSNotificationCenter defaultCenter] postNotificationName:@"changedAccount" object:nil];
  75.  
  76.  
  77.  
  78. [self.navigationController popViewControllerAnimated:YES];
  79. [[[self.navigationController viewControllers] objectAtIndex:0] reloadData];
  80. }
  81.  
  82. - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
  83. {
  84. NSLog(@"user info = %@", userInfo);
  85. if([[userInfo objectAtIndex:0] objectForKey:@"id"] != nil)
  86. {
  87. [HUD setText:@"Validated"];
  88. [HUD done];
  89. [HUD setNeedsDisplay];
  90. [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
  91.  
  92. NSDictionary *accountInfo = [[NSDictionary alloc] initWithObjectsAndKeys: username.text, @"username", password.text, @"password",nil];
  93. [[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"AccountsArray"] addObject:accountInfo];
  94.  
  95. NSLog(@"%@", [[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"]);
  96. [[[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"] writeToFile:@"/Users/Mac/Desktop/Test.txt" atomically:YES];
  97.  
  98. [[NSUserDefaults standardUserDefaults] setObject:username.text forKey:@"username"];
  99. [[NSUserDefaults standardUserDefaults] setObject:password.text forKey:@"password"];
  100. [[NSUserDefaults standardUserDefaults] synchronize];
  101.  
  102. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TwitFirstLaunch"];
  103.  
  104. [[NSNotificationCenter defaultCenter] postNotificationName:@"changedAccount" object:nil];
  105.  
  106.  
  107.  
  108. [self.navigationController popViewControllerAnimated:YES];
  109. [[[self.navigationController viewControllers] objectAtIndex:0] reloadData];
  110. //[self.navigationController popToRootViewControllerAnimated:YES];
  111.  
  112.  
  113.  
  114.  
  115. /*
  116. AccountSettings *anotherViewController = [[AccountSettings alloc] initWithNibName:@"AccountSettings" bundle:[NSBundle mainBundle]];
  117. [anotherViewController setTitle:@"Manage Accounts"];
  118. if([[NSUserDefaults standardUserDefaults] boolForKey:@"TwibaFirstLaunch"] == YES){
  119.  
  120. }else{
  121. [self.navigationController pushViewController:anotherViewController animated:YES];
  122. }
  123. [anotherViewController release];
  124. */
  125. }
  126. }
  127.  
  128. - (void) killHUD: (id)aHUD
  129. {
  130. [aHUD hide];
  131. [aHUD removeFromSuperview];
  132. [aHUD release];
  133. }
  134.  
  135.  
  136. - (void)didReceiveMemoryWarning {
  137. // Releases the view if it doesn't have a superview.
  138. [super didReceiveMemoryWarning];
  139.  
  140. // Release any cached data, images, etc that aren't in use.
  141. }
  142.  
  143. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  144. {
  145. return YES;
  146.  
  147. }
  148.  
  149.  
  150. - (void)dealloc {
  151. [engine release];
  152. [super dealloc];
  153. }
  154.  
  155.  
  156. @end
Add Comment
Please, Sign In to add comment