constants, errors produce alert
This commit is contained in:
parent
bc41170675
commit
a41b939b99
@ -2,4 +2,22 @@
|
||||
<Bucket
|
||||
type = "0"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "FMC Planner 2/DropboxV2ObjC.m"
|
||||
timestampString = "481396548.273272"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "78"
|
||||
endingLineNumber = "78"
|
||||
landmarkName = "-deauthorizeUserWithPresenter:"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -73,7 +73,8 @@
|
||||
completion:^(void) {
|
||||
[_smWebView.navigationController
|
||||
popViewControllerAnimated:YES];
|
||||
}];
|
||||
}
|
||||
presenter:nil];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -22,19 +22,24 @@
|
||||
|
||||
#pragma mark - Authorization methods
|
||||
|
||||
- (BOOL)authorizeUserWithToke:(NSURL *)token completion:(void (^)(void))handler;
|
||||
- (void)deauthorizeUser;
|
||||
- (BOOL)authorizeUserWithToke:(NSURL *)token
|
||||
completion:(void (^)(void))handler
|
||||
presenter:(UIViewController *)presenter;
|
||||
- (void)deauthorizeUserWithPresenter:(UIViewController *)presenter;
|
||||
|
||||
#pragma mark - File and directory methods
|
||||
|
||||
- (void)downloadFromDropbox:(NSArray *)files;
|
||||
- (void)uploadToDropbox:(NSArray *)files;
|
||||
- (void)downloadFromDropbox:(NSArray *)files
|
||||
presenter:(UIViewController *)presenter;
|
||||
- (void)uploadToDropbox:(NSArray *)files
|
||||
presenter:(UIViewController *)presenter;
|
||||
- (void)contentsOfPath:(NSString *)path
|
||||
completion:(void (^)(NSArray *data))handler;
|
||||
completion:(void (^)(NSArray *data))handler
|
||||
presenter:(UIViewController *)presenter;
|
||||
|
||||
#pragma mark - Other methods
|
||||
|
||||
- (NSDictionary *)getUserInfo;
|
||||
- (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter;
|
||||
|
||||
|
||||
@end
|
||||
@ -25,8 +25,9 @@
|
||||
}
|
||||
|
||||
#pragma mark - OAuth stuff
|
||||
// TODO: Alert on error
|
||||
- (BOOL)authorizeUserWithToke:(NSURL *)token completion:(void (^)(void))handler
|
||||
- (BOOL)authorizeUserWithToke:(NSURL *)token
|
||||
completion:(void (^)(void))handler
|
||||
presenter:(UIViewController *)presenter
|
||||
{
|
||||
NSScanner *scan = [NSScanner scannerWithString:token.absoluteString];
|
||||
NSString *error = [[NSString alloc] init];
|
||||
@ -53,8 +54,7 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
- (void)deauthorizeUser
|
||||
- (void)deauthorizeUserWithPresenter:(UIViewController *)presenter
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
request.URL = [NSURL
|
||||
@ -75,7 +75,8 @@
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error) {
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
if (data != nil &&
|
||||
[[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
isEqualToDictionary:@{}]) {
|
||||
@ -89,6 +90,29 @@
|
||||
removeCredential:credential
|
||||
forProtectionSpace:_kDropboxProtectionSpace];
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
|
||||
}];
|
||||
}
|
||||
else if (![[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
isEqualToDictionary:@{}]) {
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:@{
|
||||
DropboxErrorUserInfo :
|
||||
NSLocalizedDescriptionKey
|
||||
}]
|
||||
|
||||
presenter:presenter];
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
@ -98,9 +122,10 @@
|
||||
* Pass nil as path for root dir
|
||||
* @param completion executed after completion
|
||||
*/
|
||||
// TODO: Alert on error
|
||||
// TODO: Alert on Dropbox error
|
||||
- (void)contentsOfPath:(NSString *)path
|
||||
completion:(void (^)(NSArray *data))handler
|
||||
presenter:(UIViewController *)presenter
|
||||
{
|
||||
|
||||
if (path == nil) {
|
||||
@ -133,22 +158,33 @@
|
||||
temp = [temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
|
||||
request.HTTPBody = [temp dataUsingEncoding:NSASCIIStringEncoding];
|
||||
|
||||
[NSURLConnection sendAsynchronousRequest:request
|
||||
[NSURLConnection
|
||||
sendAsynchronousRequest:request
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
completionHandler:^(NSURLResponse *response,
|
||||
NSData *data, NSError *error) {
|
||||
data =
|
||||
[NSJSONSerialization JSONObjectWithData:data
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error) {
|
||||
if (data != nil) {
|
||||
data = [NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil];
|
||||
if ([data isKindOfClass:[NSDictionary class]]) {
|
||||
handler([data valueForKey:@"entries"]);
|
||||
}
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
// TODO: Alert on Dropbox error
|
||||
- (void)downloadFromDropbox:(NSArray *)files
|
||||
presenter:(UIViewController *)presenter
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
request.URL = [NSURL
|
||||
@ -189,13 +225,21 @@
|
||||
savePathForFile:string]
|
||||
atomically:YES];
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Alert on error
|
||||
- (void)uploadToDropbox:(NSArray *)files
|
||||
// TODO: Alert on Dropbox error
|
||||
- (void)uploadToDropbox:(NSArray *)files presenter:(UIViewController *)presenter
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
request.URL =
|
||||
@ -234,7 +278,15 @@
|
||||
sendAsynchronousRequest:request
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error){
|
||||
NSError *error) {
|
||||
if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
@ -242,8 +294,8 @@
|
||||
#pragma mark - Other operations
|
||||
|
||||
// !!!: Cannot be asynchronous
|
||||
// TODO: Alert on error
|
||||
- (NSDictionary *)getUserInfo
|
||||
// TODO: Alert on Dropbox error
|
||||
- (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter
|
||||
{
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||
request.URL =
|
||||
@ -262,12 +314,21 @@
|
||||
|
||||
NSURLResponse *response = nil;
|
||||
NSError *error = nil;
|
||||
NSError *error2 = nil;
|
||||
id data = [self parseJSON:[NSURLConnection sendSynchronousRequest:request
|
||||
returningResponse:&response
|
||||
error:&error]];
|
||||
error:&error2]];
|
||||
if ([data isKindOfClass:[NSDictionary class]]) {
|
||||
return data;
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error presenter:presenter];
|
||||
|
||||
}];
|
||||
return nil;
|
||||
}
|
||||
else {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@ -10,16 +10,12 @@
|
||||
|
||||
@interface SharedDeclerations : NSObject
|
||||
|
||||
#pragma mark - Route page management macros
|
||||
#pragma mark - Route page management constants
|
||||
|
||||
#define FOO1 NEXTRTEPAGE
|
||||
#define STRINGIZE(x) #x
|
||||
#define STRINGIZE2(x) STRINGIZE(x)
|
||||
#define FMCNEXTRTEPAGE @STRINGIZE2(FOO1)
|
||||
#define FOO2 FIRSTRTEPAGE
|
||||
#define STRINGIZE(x) #x
|
||||
#define STRINGIZE2(x) STRINGIZE(x)
|
||||
#define FMCFIRSTRTEPAGE @STRINGIZE2(FOO2)
|
||||
extern NSString *const FMCNEXTRTEPAGE;
|
||||
extern NSString *const FMCFIRSTRTEPAGE;
|
||||
extern NSString *const DropboxErrorDomain;
|
||||
extern NSString *const DropboxErrorUserInfo;
|
||||
|
||||
#pragma mark - Adaptive font size method
|
||||
|
||||
@ -31,4 +27,9 @@
|
||||
|
||||
+ (NSString *)savePathForFile:(NSString *)file;
|
||||
|
||||
#pragma mark - Alert for handling displaying Eroor Messages.
|
||||
|
||||
+ (void)presentErrorAlert:(NSError *)error
|
||||
presenter:(UIViewController *)presenter;
|
||||
|
||||
@end
|
||||
|
||||
@ -10,6 +10,12 @@
|
||||
|
||||
@implementation SharedDeclerations
|
||||
|
||||
NSString *const FMCNEXTRTEPAGE = @"NEXTRTEPAGE";
|
||||
NSString *const FMCFIRSTRTEPAGE = @"FIRSTRTEPAGE";
|
||||
NSString *const DropboxErrorDomain = @"com.weebly.alikja.FMC";
|
||||
NSString *const DropboxErrorUserInfo =
|
||||
@"Dropbox API Error. Please try again later!";
|
||||
|
||||
#pragma mark - Adaptive font size method
|
||||
|
||||
+ (UIFont *)findAdaptiveFontForUILabelSize:(CGSize)labelSize
|
||||
@ -65,4 +71,33 @@
|
||||
stringByAppendingString:[NSString stringWithFormat:@"/%@", file]];
|
||||
}
|
||||
|
||||
#pragma mark - Alert for handling displaying Eroor Messages.
|
||||
|
||||
+ (void)presentErrorAlert:(NSError *)error
|
||||
presenter:(UIViewController *)presenter
|
||||
{
|
||||
if ([UIAlertController class]) {
|
||||
UIAlertController *alert = [UIAlertController
|
||||
alertControllerWithTitle:@"Error"
|
||||
message:error.localizedDescription
|
||||
preferredStyle:UIAlertControllerStyleActionSheet];
|
||||
UIAlertAction *defaultAction =
|
||||
[UIAlertAction actionWithTitle:@"OK"
|
||||
style:UIAlertActionStyleCancel
|
||||
handler:nil];
|
||||
[alert addAction:defaultAction];
|
||||
|
||||
[presenter presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
else {
|
||||
UIAlertView *alert =
|
||||
[[UIAlertView alloc] initWithTitle:@"Error"
|
||||
message:error.localizedDescription
|
||||
delegate:nil
|
||||
cancelButtonTitle:@"Cancel"
|
||||
otherButtonTitles:nil];
|
||||
[alert show];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -56,7 +56,8 @@ DropboxV2ObjC *dbClient = nil;
|
||||
predicateWithFormat:@"NOT (SELF BEGINSWITH %@)",
|
||||
@"."]] mutableCopy];
|
||||
[self.tableView reloadData];
|
||||
}];
|
||||
}
|
||||
presenter:self];
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,11 +170,11 @@ DropboxV2ObjC *dbClient = nil;
|
||||
- (void)finishSelection
|
||||
{
|
||||
if ([self.title isEqualToString:@"Download"]) {
|
||||
[dbClient downloadFromDropbox:_markList];
|
||||
[dbClient downloadFromDropbox:_markList presenter:self];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
if ([self.title isEqualToString:@"Upload"]) {
|
||||
[dbClient uploadToDropbox:_markList];
|
||||
[dbClient uploadToDropbox:_markList presenter:self];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@
|
||||
{
|
||||
DropboxV2ObjC *dbClient =
|
||||
((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient;
|
||||
[dbClient deauthorizeUser];
|
||||
[dbClient deauthorizeUserWithPresenter:self];
|
||||
[_dbConnectButton setTitle:@"Connect to Dropbox"
|
||||
forState:UIControlStateNormal];
|
||||
[_dbConnectButton removeTarget:self
|
||||
@ -96,8 +96,9 @@
|
||||
[dbClient contentsOfPath:nil
|
||||
completion:^(NSArray *data) {
|
||||
NSLog(@"%@", data);
|
||||
}];
|
||||
[dbClient uploadToDropbox:@[ @"EDDFEDDM001" ]];
|
||||
}
|
||||
presenter:self];
|
||||
[dbClient uploadToDropbox:@[ @"EDDFEDDM001" ] presenter:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -6,8 +6,6 @@
|
||||
// Copyright © 2016 Kilian Hofmann. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "DropboxV2ObjC.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
@interface FMC_Planner_2Tests : XCTestCase
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user