Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id HUD;
- - (void)viewWillAppear:(BOOL)animated
- {
- [username becomeFirstResponder];
- self.title = @"New User";
- [[[self.navigationController viewControllers] objectAtIndex:0] hideError];
- }
- - (CGSize)contentSizeForViewInPopover
- {
- return CGSizeMake(400.0, 400.0);
- }
- - (IBAction)addAccount:(id)sender{
- engine = [[MGTwitterEngine alloc] initWithDelegate:self];
- [engine setUsesSecureConnection:YES];
- [engine setConsumerKey:@"vobfhfyZPjkKufUFS235Hg"
- secret:@"hnabIs54MXaJZbtA6yACn8bVUkm9jeyrkcnrU7jRi4"];
- [engine getXAuthAccessTokenForUsername:username.text password:password.text];
- [password resignFirstResponder];
- [username resignFirstResponder];
- HUD = [[UIProgressHUD alloc] initWithFrame:CGRectMake((self.view.bounds.size.width/2)-100, (self.view.bounds.size.height/2)-60, 200, 120)];
- [self.view addSubview:HUD];
- [HUD setText:@"Authorizing"];
- [HUD show:YES];
- }
- #pragma mark MGTwitterEngineDelegate methods
- - (void)requestSucceeded:(NSString *)connectionIdentifier
- {
- NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
- }
- - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error
- {
- NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
- connectionIdentifier,
- [error localizedDescription],
- [error userInfo]);
- [HUD setText:@"Error"];
- [HUD setNeedsDisplay];
- [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
- }
- - (void)accessTokenReceived:(OAToken *)aToken forRequest:(NSString *)connectionIdentifier {
- token = aToken;
- [engine setAccessToken:token];
- [HUD setText:@"Validated"];
- [HUD done];
- [HUD setNeedsDisplay];
- [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
- NSDictionary *accountInfo = [[NSDictionary alloc] initWithObjectsAndKeys: username.text, @"username", password.text, @"password",nil];
- [[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"AccountsArray"] addObject:accountInfo];
- NSLog(@"%@", [[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"]);
- [[[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"] writeToFile:@"/Users/Mac/Desktop/Test.txt" atomically:YES];
- [[NSUserDefaults standardUserDefaults] setObject:username.text forKey:@"username"];
- [[NSUserDefaults standardUserDefaults] setObject:password.text forKey:@"password"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TwitFirstLaunch"];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changedAccount" object:nil];
- [self.navigationController popViewControllerAnimated:YES];
- [[[self.navigationController viewControllers] objectAtIndex:0] reloadData];
- }
- - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
- {
- NSLog(@"user info = %@", userInfo);
- if([[userInfo objectAtIndex:0] objectForKey:@"id"] != nil)
- {
- [HUD setText:@"Validated"];
- [HUD done];
- [HUD setNeedsDisplay];
- [self performSelector:@selector(killHUD:) withObject:HUD afterDelay:1.5];
- NSDictionary *accountInfo = [[NSDictionary alloc] initWithObjectsAndKeys: username.text, @"username", password.text, @"password",nil];
- [[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"AccountsArray"] addObject:accountInfo];
- NSLog(@"%@", [[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"]);
- [[[NSUserDefaults standardUserDefaults] arrayForKey:@"AccountsArray"] writeToFile:@"/Users/Mac/Desktop/Test.txt" atomically:YES];
- [[NSUserDefaults standardUserDefaults] setObject:username.text forKey:@"username"];
- [[NSUserDefaults standardUserDefaults] setObject:password.text forKey:@"password"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TwitFirstLaunch"];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changedAccount" object:nil];
- [self.navigationController popViewControllerAnimated:YES];
- [[[self.navigationController viewControllers] objectAtIndex:0] reloadData];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- /*
- AccountSettings *anotherViewController = [[AccountSettings alloc] initWithNibName:@"AccountSettings" bundle:[NSBundle mainBundle]];
- [anotherViewController setTitle:@"Manage Accounts"];
- if([[NSUserDefaults standardUserDefaults] boolForKey:@"TwibaFirstLaunch"] == YES){
- }else{
- [self.navigationController pushViewController:anotherViewController animated:YES];
- }
- [anotherViewController release];
- */
- }
- }
- - (void) killHUD: (id)aHUD
- {
- [aHUD hide];
- [aHUD removeFromSuperview];
- [aHUD release];
- }
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return YES;
- }
- - (void)dealloc {
- [engine release];
- [super dealloc];
- }
- @end
Add Comment
Please, Sign In to add comment