Approach to managing multiple services like Evernote, Google drive, dropbox in iOS

I’m trying to think up a scenario when I’d have three different forms of NSData (or whatever) to be sent to three different services like Evernote, Google drive, Dropbox. Granted, each of those has there own SDKs to be bundled into the iOS app, and thats okay.

Now, I want to create a single Class that serialises the both sending and receiving data to and from the above services.

My mind is taking me to a singleton, a shared class with NSOperationQueue at its foundation.

I’d periodically add {send:"this data" to:dropbox} into an NSOperationBlock and add it to the singleton.

At any given time say the following operations could be within the singleton‘s NSOperationQueue.

  • {send:"this data" to:dropbox}
  • {send:"this number" to:evernote}
  • {send:"this dude" to:googledrive}

The singleton would need to handle internet reachability, app sessions etc. This class would be connected to Dropbox, Evernote and GDrive and their respective SDK bundles. So, in reality the only thing this class would do is, hand over the data to the respective SDKs to handle it on their own (which is like saying, handle it and let me know if it was a success or failed.)

I’d really like suggestions/critique on the approach i’m taking. I have little experience with NSOperationQueue, I don’t know if I’m making the right choices here. Some clues to a good API pattern would really be helpful.

UPDATE

It was suggested I create a wrapper for each service. But If can stress that theres little to do in a Dropbox Wrapper classes, Since in iOS everything is handled in their own SDK. For example, Evernote extends only a simple [ENSession .. uploadNote..]. All I wanted to do, is serialise my uploads into a single global queue and then dispatch the single methods to either Dropbox or Evernote or wherever. If suppose there is a service that requires some form of data handling, I’d then use a wrapper and dispatch its own thread. I’ll add this into the question too. Its the serialising & queueing I want.Sounds reasonable?

4

Break the services into their own respective classes. Even if a class only has one function in it, it will add much better readability, and thus scalability and be readily editable in the future. Stick to the Unix philosophy that each class should do only one thing, and do that one thing well. So I would have one class handle internet reachability using the notification center and three classes for each service. For example, here is a singleton class I once used with Google Drive.

#import <Foundation/Foundation.h>

#import "GTLDrive.h"
#import "GTMOAuth2Authentication.h"
#import "VSGConstants.h"

@interface VSGGoogleServiceDrive : GTLServiceDrive

/**
 Static method for having a shared Google service across the app
 */
+ (VSGGoogleServiceDrive *)sharedService;

@end

#import "VSGGoogleServiceDrive.h"

@implementation VSGGoogleServiceDrive

+ (VSGGoogleServiceDrive *)sharedService {

    static VSGGoogleServiceDrive *sharedServiceDrive = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedServiceDrive = [[VSGGoogleServiceDrive alloc] init];
    });
    return sharedServiceDrive;
}


- (id)init {

    self = [super init];
    if (!self){
        return nil;
    }
    GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
    auth.accessToken = GOOGLE_ACCESS_TOKEN;
    auth.refreshToken = GOOGLE_REFRESH_TOKEN;
    auth.tokenURL = [NSURL URLWithString:GOOGLE_TOKEN_URL];
    auth.clientID = GOOGLE_CLIENT_ID;
    auth.clientSecret = GOOGLE_CLIENT_SECRET;
    self.authorizer = auth;
    return self;
}

@end

Extremely simple, but the individual service is nicely decoupled, making it more plug-n-play. This was from an old app so with my xp now, I would go ahead and also implement my service functions here such as uploading NSData to drive or deleting folders/files, etc.

I was also using the Google Calendar service, but kept that in it’s own singleton as well.

Here’s also my Reachability class using Tony Million’s Reachability.

#import "Reachability.h"
#import "VSGConstants.h"

/**
 This class is used to monitor network connection. Dependent on the Reachability class. Provides an
 alert view to the user detailing the network connection upon network changes (disconnect/connect).
 */
@interface VSGNetworkMonitor : NSObject

/**
 Network used to check whether there is a valid connection to the server
 */
@property Reachability *network;

- (void)startMonitoringNetwork;

@end

    #import "VSGNetworkMonitor.h"

@interface VSGNetworkMonitor()

- (void)checkNetworkStatus:(NSNotification *)notice;

@end


@implementation VSGNetworkMonitor

static NSString *CONNECTION_LOST_TITLE = @"Connection Lost";
static NSString *CONNECTION_LOST_MESSAGE = @"Unable to connect to the server. Please check your connection";

static NSString *NO_CONNECTION_TITLE = @"Network Issue";
static NSString *NO_CONNECTION_MESSAGE = @"No valid internet connection detected";

static NSString *CONNECTION_FOUND_TITLE = @"Connection Found";
static NSString *CONNECTION_FOUND_MESSAGE = @"Connection to the server restored";

- (id)init {

    self = [super init];

    if(!self) {

        return nil;
    }

    self.network = [Reachability reachabilityWithHostname:SERVER_IP];

    if([self.network currentReachabilityStatus] == NotReachable) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NO_CONNECTION_TITLE
                                                        message:NO_CONNECTION_MESSAGE
                                                       delegate:self
                                              cancelButtonTitle:OK_BUTTON
                                              otherButtonTitles:nil];
        [alert show];
    }

    return self;
}


- (void)startMonitoringNetwork {

    [self.network startNotifier];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(checkNetworkStatus:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
}


- (void)checkNetworkStatus:(NSNotification *)notice {

    NetworkStatus internetStatus = [self.network currentReachabilityStatus];
    switch (internetStatus) {

        case NotReachable: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_LOST_TITLE
                                                            message:CONNECTION_LOST_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }

        case ReachableViaWiFi:
        case ReachableViaWWAN: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_FOUND_TITLE
                                                            message:CONNECTION_FOUND_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }
    }
}


@end

Don’t avoid breaking things apart. Instead, to the contrary, break things apart as much as you can. This also helps with Information Hiding as well.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Approach to managing multiple services like Evernote, Google drive, dropbox in iOS

I’m trying to think up a scenario when I’d have three different forms of NSData (or whatever) to be sent to three different services like Evernote, Google drive, Dropbox. Granted, each of those has there own SDKs to be bundled into the iOS app, and thats okay.

Now, I want to create a single Class that serialises the both sending and receiving data to and from the above services.

My mind is taking me to a singleton, a shared class with NSOperationQueue at its foundation.

I’d periodically add {send:"this data" to:dropbox} into an NSOperationBlock and add it to the singleton.

At any given time say the following operations could be within the singleton‘s NSOperationQueue.

  • {send:"this data" to:dropbox}
  • {send:"this number" to:evernote}
  • {send:"this dude" to:googledrive}

The singleton would need to handle internet reachability, app sessions etc. This class would be connected to Dropbox, Evernote and GDrive and their respective SDK bundles. So, in reality the only thing this class would do is, hand over the data to the respective SDKs to handle it on their own (which is like saying, handle it and let me know if it was a success or failed.)

I’d really like suggestions/critique on the approach i’m taking. I have little experience with NSOperationQueue, I don’t know if I’m making the right choices here. Some clues to a good API pattern would really be helpful.

UPDATE

It was suggested I create a wrapper for each service. But If can stress that theres little to do in a Dropbox Wrapper classes, Since in iOS everything is handled in their own SDK. For example, Evernote extends only a simple [ENSession .. uploadNote..]. All I wanted to do, is serialise my uploads into a single global queue and then dispatch the single methods to either Dropbox or Evernote or wherever. If suppose there is a service that requires some form of data handling, I’d then use a wrapper and dispatch its own thread. I’ll add this into the question too. Its the serialising & queueing I want.Sounds reasonable?

4

Break the services into their own respective classes. Even if a class only has one function in it, it will add much better readability, and thus scalability and be readily editable in the future. Stick to the Unix philosophy that each class should do only one thing, and do that one thing well. So I would have one class handle internet reachability using the notification center and three classes for each service. For example, here is a singleton class I once used with Google Drive.

#import <Foundation/Foundation.h>

#import "GTLDrive.h"
#import "GTMOAuth2Authentication.h"
#import "VSGConstants.h"

@interface VSGGoogleServiceDrive : GTLServiceDrive

/**
 Static method for having a shared Google service across the app
 */
+ (VSGGoogleServiceDrive *)sharedService;

@end

#import "VSGGoogleServiceDrive.h"

@implementation VSGGoogleServiceDrive

+ (VSGGoogleServiceDrive *)sharedService {

    static VSGGoogleServiceDrive *sharedServiceDrive = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedServiceDrive = [[VSGGoogleServiceDrive alloc] init];
    });
    return sharedServiceDrive;
}


- (id)init {

    self = [super init];
    if (!self){
        return nil;
    }
    GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
    auth.accessToken = GOOGLE_ACCESS_TOKEN;
    auth.refreshToken = GOOGLE_REFRESH_TOKEN;
    auth.tokenURL = [NSURL URLWithString:GOOGLE_TOKEN_URL];
    auth.clientID = GOOGLE_CLIENT_ID;
    auth.clientSecret = GOOGLE_CLIENT_SECRET;
    self.authorizer = auth;
    return self;
}

@end

Extremely simple, but the individual service is nicely decoupled, making it more plug-n-play. This was from an old app so with my xp now, I would go ahead and also implement my service functions here such as uploading NSData to drive or deleting folders/files, etc.

I was also using the Google Calendar service, but kept that in it’s own singleton as well.

Here’s also my Reachability class using Tony Million’s Reachability.

#import "Reachability.h"
#import "VSGConstants.h"

/**
 This class is used to monitor network connection. Dependent on the Reachability class. Provides an
 alert view to the user detailing the network connection upon network changes (disconnect/connect).
 */
@interface VSGNetworkMonitor : NSObject

/**
 Network used to check whether there is a valid connection to the server
 */
@property Reachability *network;

- (void)startMonitoringNetwork;

@end

    #import "VSGNetworkMonitor.h"

@interface VSGNetworkMonitor()

- (void)checkNetworkStatus:(NSNotification *)notice;

@end


@implementation VSGNetworkMonitor

static NSString *CONNECTION_LOST_TITLE = @"Connection Lost";
static NSString *CONNECTION_LOST_MESSAGE = @"Unable to connect to the server. Please check your connection";

static NSString *NO_CONNECTION_TITLE = @"Network Issue";
static NSString *NO_CONNECTION_MESSAGE = @"No valid internet connection detected";

static NSString *CONNECTION_FOUND_TITLE = @"Connection Found";
static NSString *CONNECTION_FOUND_MESSAGE = @"Connection to the server restored";

- (id)init {

    self = [super init];

    if(!self) {

        return nil;
    }

    self.network = [Reachability reachabilityWithHostname:SERVER_IP];

    if([self.network currentReachabilityStatus] == NotReachable) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NO_CONNECTION_TITLE
                                                        message:NO_CONNECTION_MESSAGE
                                                       delegate:self
                                              cancelButtonTitle:OK_BUTTON
                                              otherButtonTitles:nil];
        [alert show];
    }

    return self;
}


- (void)startMonitoringNetwork {

    [self.network startNotifier];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(checkNetworkStatus:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
}


- (void)checkNetworkStatus:(NSNotification *)notice {

    NetworkStatus internetStatus = [self.network currentReachabilityStatus];
    switch (internetStatus) {

        case NotReachable: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_LOST_TITLE
                                                            message:CONNECTION_LOST_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }

        case ReachableViaWiFi:
        case ReachableViaWWAN: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_FOUND_TITLE
                                                            message:CONNECTION_FOUND_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }
    }
}


@end

Don’t avoid breaking things apart. Instead, to the contrary, break things apart as much as you can. This also helps with Information Hiding as well.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Approach to managing multiple services like Evernote, Google drive, dropbox in iOS

I’m trying to think up a scenario when I’d have three different forms of NSData (or whatever) to be sent to three different services like Evernote, Google drive, Dropbox. Granted, each of those has there own SDKs to be bundled into the iOS app, and thats okay.

Now, I want to create a single Class that serialises the both sending and receiving data to and from the above services.

My mind is taking me to a singleton, a shared class with NSOperationQueue at its foundation.

I’d periodically add {send:"this data" to:dropbox} into an NSOperationBlock and add it to the singleton.

At any given time say the following operations could be within the singleton‘s NSOperationQueue.

  • {send:"this data" to:dropbox}
  • {send:"this number" to:evernote}
  • {send:"this dude" to:googledrive}

The singleton would need to handle internet reachability, app sessions etc. This class would be connected to Dropbox, Evernote and GDrive and their respective SDK bundles. So, in reality the only thing this class would do is, hand over the data to the respective SDKs to handle it on their own (which is like saying, handle it and let me know if it was a success or failed.)

I’d really like suggestions/critique on the approach i’m taking. I have little experience with NSOperationQueue, I don’t know if I’m making the right choices here. Some clues to a good API pattern would really be helpful.

UPDATE

It was suggested I create a wrapper for each service. But If can stress that theres little to do in a Dropbox Wrapper classes, Since in iOS everything is handled in their own SDK. For example, Evernote extends only a simple [ENSession .. uploadNote..]. All I wanted to do, is serialise my uploads into a single global queue and then dispatch the single methods to either Dropbox or Evernote or wherever. If suppose there is a service that requires some form of data handling, I’d then use a wrapper and dispatch its own thread. I’ll add this into the question too. Its the serialising & queueing I want.Sounds reasonable?

4

Break the services into their own respective classes. Even if a class only has one function in it, it will add much better readability, and thus scalability and be readily editable in the future. Stick to the Unix philosophy that each class should do only one thing, and do that one thing well. So I would have one class handle internet reachability using the notification center and three classes for each service. For example, here is a singleton class I once used with Google Drive.

#import <Foundation/Foundation.h>

#import "GTLDrive.h"
#import "GTMOAuth2Authentication.h"
#import "VSGConstants.h"

@interface VSGGoogleServiceDrive : GTLServiceDrive

/**
 Static method for having a shared Google service across the app
 */
+ (VSGGoogleServiceDrive *)sharedService;

@end

#import "VSGGoogleServiceDrive.h"

@implementation VSGGoogleServiceDrive

+ (VSGGoogleServiceDrive *)sharedService {

    static VSGGoogleServiceDrive *sharedServiceDrive = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedServiceDrive = [[VSGGoogleServiceDrive alloc] init];
    });
    return sharedServiceDrive;
}


- (id)init {

    self = [super init];
    if (!self){
        return nil;
    }
    GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
    auth.accessToken = GOOGLE_ACCESS_TOKEN;
    auth.refreshToken = GOOGLE_REFRESH_TOKEN;
    auth.tokenURL = [NSURL URLWithString:GOOGLE_TOKEN_URL];
    auth.clientID = GOOGLE_CLIENT_ID;
    auth.clientSecret = GOOGLE_CLIENT_SECRET;
    self.authorizer = auth;
    return self;
}

@end

Extremely simple, but the individual service is nicely decoupled, making it more plug-n-play. This was from an old app so with my xp now, I would go ahead and also implement my service functions here such as uploading NSData to drive or deleting folders/files, etc.

I was also using the Google Calendar service, but kept that in it’s own singleton as well.

Here’s also my Reachability class using Tony Million’s Reachability.

#import "Reachability.h"
#import "VSGConstants.h"

/**
 This class is used to monitor network connection. Dependent on the Reachability class. Provides an
 alert view to the user detailing the network connection upon network changes (disconnect/connect).
 */
@interface VSGNetworkMonitor : NSObject

/**
 Network used to check whether there is a valid connection to the server
 */
@property Reachability *network;

- (void)startMonitoringNetwork;

@end

    #import "VSGNetworkMonitor.h"

@interface VSGNetworkMonitor()

- (void)checkNetworkStatus:(NSNotification *)notice;

@end


@implementation VSGNetworkMonitor

static NSString *CONNECTION_LOST_TITLE = @"Connection Lost";
static NSString *CONNECTION_LOST_MESSAGE = @"Unable to connect to the server. Please check your connection";

static NSString *NO_CONNECTION_TITLE = @"Network Issue";
static NSString *NO_CONNECTION_MESSAGE = @"No valid internet connection detected";

static NSString *CONNECTION_FOUND_TITLE = @"Connection Found";
static NSString *CONNECTION_FOUND_MESSAGE = @"Connection to the server restored";

- (id)init {

    self = [super init];

    if(!self) {

        return nil;
    }

    self.network = [Reachability reachabilityWithHostname:SERVER_IP];

    if([self.network currentReachabilityStatus] == NotReachable) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NO_CONNECTION_TITLE
                                                        message:NO_CONNECTION_MESSAGE
                                                       delegate:self
                                              cancelButtonTitle:OK_BUTTON
                                              otherButtonTitles:nil];
        [alert show];
    }

    return self;
}


- (void)startMonitoringNetwork {

    [self.network startNotifier];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(checkNetworkStatus:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
}


- (void)checkNetworkStatus:(NSNotification *)notice {

    NetworkStatus internetStatus = [self.network currentReachabilityStatus];
    switch (internetStatus) {

        case NotReachable: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_LOST_TITLE
                                                            message:CONNECTION_LOST_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }

        case ReachableViaWiFi:
        case ReachableViaWWAN: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_FOUND_TITLE
                                                            message:CONNECTION_FOUND_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }
    }
}


@end

Don’t avoid breaking things apart. Instead, to the contrary, break things apart as much as you can. This also helps with Information Hiding as well.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Approach to managing multiple services like Evernote, Google drive, dropbox in iOS

I’m trying to think up a scenario when I’d have three different forms of NSData (or whatever) to be sent to three different services like Evernote, Google drive, Dropbox. Granted, each of those has there own SDKs to be bundled into the iOS app, and thats okay.

Now, I want to create a single Class that serialises the both sending and receiving data to and from the above services.

My mind is taking me to a singleton, a shared class with NSOperationQueue at its foundation.

I’d periodically add {send:"this data" to:dropbox} into an NSOperationBlock and add it to the singleton.

At any given time say the following operations could be within the singleton‘s NSOperationQueue.

  • {send:"this data" to:dropbox}
  • {send:"this number" to:evernote}
  • {send:"this dude" to:googledrive}

The singleton would need to handle internet reachability, app sessions etc. This class would be connected to Dropbox, Evernote and GDrive and their respective SDK bundles. So, in reality the only thing this class would do is, hand over the data to the respective SDKs to handle it on their own (which is like saying, handle it and let me know if it was a success or failed.)

I’d really like suggestions/critique on the approach i’m taking. I have little experience with NSOperationQueue, I don’t know if I’m making the right choices here. Some clues to a good API pattern would really be helpful.

UPDATE

It was suggested I create a wrapper for each service. But If can stress that theres little to do in a Dropbox Wrapper classes, Since in iOS everything is handled in their own SDK. For example, Evernote extends only a simple [ENSession .. uploadNote..]. All I wanted to do, is serialise my uploads into a single global queue and then dispatch the single methods to either Dropbox or Evernote or wherever. If suppose there is a service that requires some form of data handling, I’d then use a wrapper and dispatch its own thread. I’ll add this into the question too. Its the serialising & queueing I want.Sounds reasonable?

4

Break the services into their own respective classes. Even if a class only has one function in it, it will add much better readability, and thus scalability and be readily editable in the future. Stick to the Unix philosophy that each class should do only one thing, and do that one thing well. So I would have one class handle internet reachability using the notification center and three classes for each service. For example, here is a singleton class I once used with Google Drive.

#import <Foundation/Foundation.h>

#import "GTLDrive.h"
#import "GTMOAuth2Authentication.h"
#import "VSGConstants.h"

@interface VSGGoogleServiceDrive : GTLServiceDrive

/**
 Static method for having a shared Google service across the app
 */
+ (VSGGoogleServiceDrive *)sharedService;

@end

#import "VSGGoogleServiceDrive.h"

@implementation VSGGoogleServiceDrive

+ (VSGGoogleServiceDrive *)sharedService {

    static VSGGoogleServiceDrive *sharedServiceDrive = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedServiceDrive = [[VSGGoogleServiceDrive alloc] init];
    });
    return sharedServiceDrive;
}


- (id)init {

    self = [super init];
    if (!self){
        return nil;
    }
    GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
    auth.accessToken = GOOGLE_ACCESS_TOKEN;
    auth.refreshToken = GOOGLE_REFRESH_TOKEN;
    auth.tokenURL = [NSURL URLWithString:GOOGLE_TOKEN_URL];
    auth.clientID = GOOGLE_CLIENT_ID;
    auth.clientSecret = GOOGLE_CLIENT_SECRET;
    self.authorizer = auth;
    return self;
}

@end

Extremely simple, but the individual service is nicely decoupled, making it more plug-n-play. This was from an old app so with my xp now, I would go ahead and also implement my service functions here such as uploading NSData to drive or deleting folders/files, etc.

I was also using the Google Calendar service, but kept that in it’s own singleton as well.

Here’s also my Reachability class using Tony Million’s Reachability.

#import "Reachability.h"
#import "VSGConstants.h"

/**
 This class is used to monitor network connection. Dependent on the Reachability class. Provides an
 alert view to the user detailing the network connection upon network changes (disconnect/connect).
 */
@interface VSGNetworkMonitor : NSObject

/**
 Network used to check whether there is a valid connection to the server
 */
@property Reachability *network;

- (void)startMonitoringNetwork;

@end

    #import "VSGNetworkMonitor.h"

@interface VSGNetworkMonitor()

- (void)checkNetworkStatus:(NSNotification *)notice;

@end


@implementation VSGNetworkMonitor

static NSString *CONNECTION_LOST_TITLE = @"Connection Lost";
static NSString *CONNECTION_LOST_MESSAGE = @"Unable to connect to the server. Please check your connection";

static NSString *NO_CONNECTION_TITLE = @"Network Issue";
static NSString *NO_CONNECTION_MESSAGE = @"No valid internet connection detected";

static NSString *CONNECTION_FOUND_TITLE = @"Connection Found";
static NSString *CONNECTION_FOUND_MESSAGE = @"Connection to the server restored";

- (id)init {

    self = [super init];

    if(!self) {

        return nil;
    }

    self.network = [Reachability reachabilityWithHostname:SERVER_IP];

    if([self.network currentReachabilityStatus] == NotReachable) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NO_CONNECTION_TITLE
                                                        message:NO_CONNECTION_MESSAGE
                                                       delegate:self
                                              cancelButtonTitle:OK_BUTTON
                                              otherButtonTitles:nil];
        [alert show];
    }

    return self;
}


- (void)startMonitoringNetwork {

    [self.network startNotifier];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(checkNetworkStatus:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];
}


- (void)checkNetworkStatus:(NSNotification *)notice {

    NetworkStatus internetStatus = [self.network currentReachabilityStatus];
    switch (internetStatus) {

        case NotReachable: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_LOST_TITLE
                                                            message:CONNECTION_LOST_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }

        case ReachableViaWiFi:
        case ReachableViaWWAN: {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CONNECTION_FOUND_TITLE
                                                            message:CONNECTION_FOUND_MESSAGE
                                                           delegate:nil
                                                  cancelButtonTitle:OK_BUTTON
                                                  otherButtonTitles:nil];
            [alert show];
            break;
        }
    }
}


@end

Don’t avoid breaking things apart. Instead, to the contrary, break things apart as much as you can. This also helps with Information Hiding as well.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật