SlideShare a Scribd company logo
1 of 25
Download to read offline
Dropbox Sync API
                                  Michael Pan



13年3月13⽇日星期三
Who am I
               E-mail : scentsome@gmail.com
               Facebook Page : Developer’s Note
               http://www.facebook.com/pages/Taipei-Taiwan/Developers-note/226724001803
               Blogger : Developer’s Note
               http://iosdevelopersnote.blogspot.com/




13年3月13⽇日星期三
Official Dropbox Sync API
           •   https://www.dropbox.com/developers/sync




13年3月13⽇日星期三
Beware
           •   Core API & Sync API can not work together




13年3月13⽇日星期三
Create a Dropbox App




13年3月13⽇日星期三
Keys




13年3月13⽇日星期三
Keys




13年3月13⽇日星期三
Tutorial
           •   https://www.dropbox.com/developers/sync/tutorial/ios




13年3月13⽇日星期三
What will we build
         •     http://www.youtube.com/watch?v=2_-L7xg0Nac




13年3月13⽇日星期三
Sync file
         •     http://www.youtube.com/watch?v=8mHEq_uR1EY




13年3月13⽇日星期三
download Framework
           •   http://bit.ly/15K6RiR




13年3月13⽇日星期三
#import <Dropbox/Dropbox.h>




13年3月13⽇日星期三
URL Scheme




13年3月13⽇日星期三
Login




13年3月13⽇日星期三
Codes - AppDelegate.m
        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
        *)launchOptions
        {
            DBAccountManager* accountMgr =
            [[DBAccountManager alloc] initWithAppKey:@"nxsss-----" secret:@"s;a;lijejjz"];
            [DBAccountManager setSharedManager:accountMgr];
            DBAccount *account = accountMgr.linkedAccount;

               if (account) {
                   DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
                   [DBFilesystem setSharedFilesystem:filesystem];
               }
               return YES;
        }
        - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
          sourceApplication:(NSString *)source annotation:(id)annotation {
            DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
            if (account) {
                DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
                [DBFilesystem setSharedFilesystem:filesystem];
                NSLog(@"App linked successfully!");
                return YES;
            }
            return NO;
        }
13年3月13⽇日星期三
View Controller
       - (IBAction)launchRemoteFile:(id)sender {

               [[DBAccountManager sharedManager] linkFromController:self.navigationController];
       }




13年3月13⽇日星期三
RemoteFileViewController




13年3月13⽇日星期三
Storyboard



               ViewController
                                RemoteFileViewController




13年3月13⽇日星期三
List file system files - Button
               NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:[DBPath
       root] error:nil];
               NSMutableArray * paths = [@[] mutableCopy];
               for (DBFileInfo *info in contents) {
                   if ([info isFolder]) {
                       NSLog(@"%@/", info.path);
                   }else{
                       NSLog(@"%@", info.path);
                   }
                   [paths addObject:info];
               }

                   RemoteFileViewController * remoteFile = [self.storyboard
       instantiateViewControllerWithIdentifier:@"RemoteFile"];
                   remoteFile.remoteFiles = paths ;
                   remoteFile.folderPath = [DBPath root];
                   [self.navigationController pushViewController:remoteFile animated:YES];


13年3月13⽇日星期三
List file system files - must in thread
       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
               NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:[DBPath
       root] error:nil];
               NSMutableArray * paths = [@[] mutableCopy];
               for (DBFileInfo *info in contents) {
                   if ([info isFolder]) {
                       NSLog(@"%@/", info.path);
                   }else{
                       NSLog(@"%@", info.path);
                   }
                   [paths addObject:info];
               }
               dispatch_async(dispatch_get_main_queue(), ^{
                   RemoteFileViewController * remoteFile = [self.storyboard
       instantiateViewControllerWithIdentifier:@"RemoteFile"];
                   remoteFile.remoteFiles = paths ;
                   remoteFile.folderPath = [DBPath root];
                   [self.navigationController pushViewController:remoteFile animated:YES];
               });
           });
13年3月13⽇日星期三
RemoteFileViewController.h
       #import <UIKit/UIKit.h>
       #import <Dropbox/Dropbox.h>
       @interface RemoteFileViewController : UITableViewController
       @property (strong) NSArray * remoteFiles; // sub files
       @property (strong) DBPath * folderPath; // Current Folder
       @end




13年3月13⽇日星期三
RemoteFileViewController.m - Observer
           - (void)viewDidLoad
           {
               [super viewDidLoad];
               [[DBFilesystem sharedFilesystem] addObserver:self
           forPathAndChildren:self.folderPath block:^{
                   [self reloadFolder];
               }];
               if (self.folderPath.name == nil || [self.folderPath.name
           isEqualToString:@""]) {
                   self.navigationItem.title = @"Root";
               }else{
                   self.navigationItem.title = self.folderPath.name;
               }
           }

           -(void) dealloc{
               [[DBFilesystem sharedFilesystem] removeObserver:self];
           }

13年3月13⽇日星期三
ReloadFolder
   -(void) reloadFolder{
       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
           NSMutableArray * files = [@[] mutableCopy];
           NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:self.folderPath
   error:nil];
           for (DBFileInfo *info in contents) {
               if ([info isFolder]) {
                   NSLog(@"%@/", info.path);
               }else{
                   NSLog(@"%@", info.path);
               }
               [files addObject:info];
           }
           dispatch_async(dispatch_get_main_queue(), ^{
               self.remoteFiles = files;
               [self.tableView reloadData];
           });
       });
   }


13年3月13⽇日星期三
TableViewCell
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [self.remoteFiles count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
    *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
    forIndexPath:indexPath];

         DBFileInfo * fileInfo = self.remoteFiles[indexPath.row];
         cell.textLabel.text = fileInfo.path.name ;
         if (fileInfo.isFolder) {
             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
         }else{
             cell.accessoryType = UITableViewCellAccessoryNone;

         }
         return cell;
    }


13年3月13⽇日星期三
Demo




13年3月13⽇日星期三

More Related Content

Similar to Dropbox sync (7)

由一个简单的程序谈起――之二
由一个简单的程序谈起――之二由一个简单的程序谈起――之二
由一个简单的程序谈起――之二
 
CRUD 綜合運用
CRUD 綜合運用CRUD 綜合運用
CRUD 綜合運用
 
Discuz技术交流
Discuz技术交流Discuz技术交流
Discuz技术交流
 
小谈Javascript设计模式
小谈Javascript设计模式小谈Javascript设计模式
小谈Javascript设计模式
 
I os 16
I os 16I os 16
I os 16
 
[DCTPE2010] Drupal 模組開發入門
[DCTPE2010] Drupal 模組開發入門[DCTPE2010] Drupal 模組開發入門
[DCTPE2010] Drupal 模組開發入門
 
Dive into kissy
Dive into kissyDive into kissy
Dive into kissy
 

More from Michael Pan

Google maps SDK for iOS 1.4
Google maps SDK for iOS 1.4Google maps SDK for iOS 1.4
Google maps SDK for iOS 1.4
Michael Pan
 
比價撿便宜 Steven
比價撿便宜 Steven比價撿便宜 Steven
比價撿便宜 Steven
Michael Pan
 
Appsgaga - iOS Game Developer
Appsgaga - iOS Game DeveloperAppsgaga - iOS Game Developer
Appsgaga - iOS Game Developer
Michael Pan
 
GZFox Inc. Jacky
GZFox Inc. JackyGZFox Inc. Jacky
GZFox Inc. Jacky
Michael Pan
 
創投公司 hoku_20121017
創投公司 hoku_20121017創投公司 hoku_20121017
創投公司 hoku_20121017
Michael Pan
 

More from Michael Pan (18)

Activity
ActivityActivity
Activity
 
Shootting Game
Shootting GameShootting Game
Shootting Game
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android Studio
 
Eclipse and Genymotion
Eclipse and GenymotionEclipse and Genymotion
Eclipse and Genymotion
 
Note something
Note somethingNote something
Note something
 
Strategy Pattern for Objective-C
Strategy Pattern for Objective-CStrategy Pattern for Objective-C
Strategy Pattern for Objective-C
 
Core data lightweight_migration
Core data lightweight_migrationCore data lightweight_migration
Core data lightweight_migration
 
Google maps SDK for iOS 1.4
Google maps SDK for iOS 1.4Google maps SDK for iOS 1.4
Google maps SDK for iOS 1.4
 
Homework2 play cards
Homework2 play cardsHomework2 play cards
Homework2 play cards
 
Prototype by Xcode
Prototype by XcodePrototype by Xcode
Prototype by Xcode
 
Nimbus
NimbusNimbus
Nimbus
 
Superstar dj pdf
Superstar dj pdfSuperstar dj pdf
Superstar dj pdf
 
ADB - Arthur
ADB - ArthurADB - Arthur
ADB - Arthur
 
比價撿便宜 Steven
比價撿便宜 Steven比價撿便宜 Steven
比價撿便宜 Steven
 
Appsgaga - iOS Game Developer
Appsgaga - iOS Game DeveloperAppsgaga - iOS Game Developer
Appsgaga - iOS Game Developer
 
GZFox Inc. Jacky
GZFox Inc. JackyGZFox Inc. Jacky
GZFox Inc. Jacky
 
創投公司 hoku_20121017
創投公司 hoku_20121017創投公司 hoku_20121017
創投公司 hoku_20121017
 
Opening iOS App 開發者交流會
Opening iOS App 開發者交流會Opening iOS App 開發者交流會
Opening iOS App 開發者交流會
 

Dropbox sync

  • 1. Dropbox Sync API Michael Pan 13年3月13⽇日星期三
  • 2. Who am I E-mail : scentsome@gmail.com Facebook Page : Developer’s Note http://www.facebook.com/pages/Taipei-Taiwan/Developers-note/226724001803 Blogger : Developer’s Note http://iosdevelopersnote.blogspot.com/ 13年3月13⽇日星期三
  • 3. Official Dropbox Sync API • https://www.dropbox.com/developers/sync 13年3月13⽇日星期三
  • 4. Beware • Core API & Sync API can not work together 13年3月13⽇日星期三
  • 5. Create a Dropbox App 13年3月13⽇日星期三
  • 8. Tutorial • https://www.dropbox.com/developers/sync/tutorial/ios 13年3月13⽇日星期三
  • 9. What will we build • http://www.youtube.com/watch?v=2_-L7xg0Nac 13年3月13⽇日星期三
  • 10. Sync file • http://www.youtube.com/watch?v=8mHEq_uR1EY 13年3月13⽇日星期三
  • 11. download Framework • http://bit.ly/15K6RiR 13年3月13⽇日星期三
  • 15. Codes - AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { DBAccountManager* accountMgr = [[DBAccountManager alloc] initWithAppKey:@"nxsss-----" secret:@"s;a;lijejjz"]; [DBAccountManager setSharedManager:accountMgr]; DBAccount *account = accountMgr.linkedAccount; if (account) { DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account]; [DBFilesystem setSharedFilesystem:filesystem]; } return YES; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation { DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url]; if (account) { DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account]; [DBFilesystem setSharedFilesystem:filesystem]; NSLog(@"App linked successfully!"); return YES; } return NO; } 13年3月13⽇日星期三
  • 16. View Controller - (IBAction)launchRemoteFile:(id)sender { [[DBAccountManager sharedManager] linkFromController:self.navigationController]; } 13年3月13⽇日星期三
  • 18. Storyboard ViewController RemoteFileViewController 13年3月13⽇日星期三
  • 19. List file system files - Button NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:[DBPath root] error:nil]; NSMutableArray * paths = [@[] mutableCopy]; for (DBFileInfo *info in contents) { if ([info isFolder]) { NSLog(@"%@/", info.path); }else{ NSLog(@"%@", info.path); } [paths addObject:info]; } RemoteFileViewController * remoteFile = [self.storyboard instantiateViewControllerWithIdentifier:@"RemoteFile"]; remoteFile.remoteFiles = paths ; remoteFile.folderPath = [DBPath root]; [self.navigationController pushViewController:remoteFile animated:YES]; 13年3月13⽇日星期三
  • 20. List file system files - must in thread dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:[DBPath root] error:nil]; NSMutableArray * paths = [@[] mutableCopy]; for (DBFileInfo *info in contents) { if ([info isFolder]) { NSLog(@"%@/", info.path); }else{ NSLog(@"%@", info.path); } [paths addObject:info]; } dispatch_async(dispatch_get_main_queue(), ^{ RemoteFileViewController * remoteFile = [self.storyboard instantiateViewControllerWithIdentifier:@"RemoteFile"]; remoteFile.remoteFiles = paths ; remoteFile.folderPath = [DBPath root]; [self.navigationController pushViewController:remoteFile animated:YES]; }); }); 13年3月13⽇日星期三
  • 21. RemoteFileViewController.h #import <UIKit/UIKit.h> #import <Dropbox/Dropbox.h> @interface RemoteFileViewController : UITableViewController @property (strong) NSArray * remoteFiles; // sub files @property (strong) DBPath * folderPath; // Current Folder @end 13年3月13⽇日星期三
  • 22. RemoteFileViewController.m - Observer - (void)viewDidLoad { [super viewDidLoad]; [[DBFilesystem sharedFilesystem] addObserver:self forPathAndChildren:self.folderPath block:^{ [self reloadFolder]; }]; if (self.folderPath.name == nil || [self.folderPath.name isEqualToString:@""]) { self.navigationItem.title = @"Root"; }else{ self.navigationItem.title = self.folderPath.name; } } -(void) dealloc{ [[DBFilesystem sharedFilesystem] removeObserver:self]; } 13年3月13⽇日星期三
  • 23. ReloadFolder -(void) reloadFolder{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ NSMutableArray * files = [@[] mutableCopy]; NSArray *contents = [[DBFilesystem sharedFilesystem] listFolder:self.folderPath error:nil]; for (DBFileInfo *info in contents) { if ([info isFolder]) { NSLog(@"%@/", info.path); }else{ NSLog(@"%@", info.path); } [files addObject:info]; } dispatch_async(dispatch_get_main_queue(), ^{ self.remoteFiles = files; [self.tableView reloadData]; }); }); } 13年3月13⽇日星期三
  • 24. TableViewCell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.remoteFiles count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; DBFileInfo * fileInfo = self.remoteFiles[indexPath.row]; cell.textLabel.text = fileInfo.path.name ; if (fileInfo.isFolder) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; }else{ cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } 13年3月13⽇日星期三