// // ViewControllerServiceMenu.m // FMC Planner 2 // // Created by Kilian Hofmann on 26.03.16. // Copyright © 2016 Kilian Hofmann. All rights reserved. // #import "ViewControllerServiceMenu.h" @implementation ViewControllerServiceMenu #pragma mark - View management and navigation - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Service Menu"; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"FMC" style:UIBarButtonItemStyleDone target:self action:@selector(back)]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; if (dbClient.token != nil) { [_dbConnectButton setTitle:@"Disconnect from Dropbox" forState:UIControlStateNormal]; [_dbConnectButton removeTarget:self action:@selector(dbConnect:) forControlEvents:UIControlEventTouchUpInside]; [_dbConnectButton addTarget:self action:@selector(dbDisconnect:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)back { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { ((TableViewController *)segue.destinationViewController).title = segue.identifier; ((TableViewController *)segue.destinationViewController).main = _main; } #pragma mark - Dropbox Button // Standard action (hence set), dnamically set and unset - (IBAction)dbConnect:(UIButton *)sender { UIViewController *webController = [[UIViewController alloc] init]; webController.title = @"Dropbox"; UIWebView *web = [[UIWebView alloc] initWithFrame:webController.view.frame]; [webController.view addSubview:web]; [self.navigationController pushViewController:webController animated:YES]; ((AppDelegate *)[UIApplication sharedApplication].delegate).smWebView = webController; [web loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"https://dropbox.com/1/oauth2/" @"authorize?response_type=token&" @"client_id=7q5bwtmi2h2iszh&redirect_" @"uri=x-fmc:/"]]]; } // Dynamically set and unset - (IBAction)dbDisconnect:(UIButton *)sender { DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; [dbClient deauthorizeUser]; [_dbConnectButton setTitle:@"Connect to Dropbox" forState:UIControlStateNormal]; [_dbConnectButton removeTarget:self action:@selector(dbDisconnect:) forControlEvents:UIControlEventTouchUpInside]; [_dbConnectButton addTarget:self action:@selector(dbConnect:) forControlEvents:UIControlEventTouchUpInside]; } #warning TESTING GROUNDS - (IBAction)testing:(id)sender { DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; NSLog(@"%@", [dbClient contentsOfPath:nil]); [dbClient downloadFromDropbox:@[ @"lol.txt", @"rofl.txt", @"tldr.txt", @"lol Kopie 3.txt" ]]; } @end