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