diff --git a/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index ed9a9b4..25ee3d8 100644
--- a/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -2,4 +2,22 @@
+
+
+
+
+
+
diff --git a/FMC Planner 2/AppDelegate.m b/FMC Planner 2/AppDelegate.m
index fb87111..c48d343 100644
--- a/FMC Planner 2/AppDelegate.m
+++ b/FMC Planner 2/AppDelegate.m
@@ -73,7 +73,8 @@
completion:^(void) {
[_smWebView.navigationController
popViewControllerAnimated:YES];
- }];
+ }
+ presenter:nil];
return YES;
}
diff --git a/FMC Planner 2/DropboxV2ObjC.h b/FMC Planner 2/DropboxV2ObjC.h
index f8a7a6d..b089301 100644
--- a/FMC Planner 2/DropboxV2ObjC.h
+++ b/FMC Planner 2/DropboxV2ObjC.h
@@ -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
\ No newline at end of file
diff --git a/FMC Planner 2/DropboxV2ObjC.m b/FMC Planner 2/DropboxV2ObjC.m
index 5809918..3b3bc3c 100644
--- a/FMC Planner 2/DropboxV2ObjC.m
+++ b/FMC Planner 2/DropboxV2ObjC.m
@@ -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
- queue:[NSOperationQueue mainQueue]
- completionHandler:^(NSURLResponse *response,
- NSData *data, NSError *error) {
- data =
- [NSJSONSerialization JSONObjectWithData:data
- options:0
- error:nil];
- if ([data isKindOfClass:[NSDictionary class]]) {
- handler([data valueForKey:@"entries"]);
- }
- }];
+ [NSURLConnection
+ sendAsynchronousRequest:request
+ queue:[NSOperationQueue mainQueue]
+ 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;
}
diff --git a/FMC Planner 2/SharedDeclerations.h b/FMC Planner 2/SharedDeclerations.h
index 262f758..d77f486 100644
--- a/FMC Planner 2/SharedDeclerations.h
+++ b/FMC Planner 2/SharedDeclerations.h
@@ -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
diff --git a/FMC Planner 2/SharedDeclerations.m b/FMC Planner 2/SharedDeclerations.m
index f9ccea1..bc16621 100644
--- a/FMC Planner 2/SharedDeclerations.m
+++ b/FMC Planner 2/SharedDeclerations.m
@@ -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
diff --git a/FMC Planner 2/TableViewController.m b/FMC Planner 2/TableViewController.m
index 9c3cb85..9d0386c 100644
--- a/FMC Planner 2/TableViewController.m
+++ b/FMC Planner 2/TableViewController.m
@@ -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];
}
}
diff --git a/FMC Planner 2/ViewControllerServiceMenu.m b/FMC Planner 2/ViewControllerServiceMenu.m
index 807c7b1..55b99ba 100644
--- a/FMC Planner 2/ViewControllerServiceMenu.m
+++ b/FMC Planner 2/ViewControllerServiceMenu.m
@@ -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
diff --git a/FMC Planner 2Tests/FMC_Planner_2Tests.m b/FMC Planner 2Tests/FMC_Planner_2Tests.m
index 5e30b1a..d2f033f 100644
--- a/FMC Planner 2Tests/FMC_Planner_2Tests.m
+++ b/FMC Planner 2Tests/FMC_Planner_2Tests.m
@@ -6,8 +6,6 @@
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
-#import "AppDelegate.h"
-#import "DropboxV2ObjC.h"
#import
@interface FMC_Planner_2Tests : XCTestCase