SlideShare a Scribd company logo
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

PDF
Autorelease pool
PDF
Objc under the_hood_2013
PPTX
iOS程序设计-数据持久化
PPTX
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
PPT
ios分享
PPT
iPhone,ios,Object-C基础入门
PPT
iPhone,ios,Object-c基础入门
PDF
旺铺前端设计和实现
Autorelease pool
Objc under the_hood_2013
iOS程序设计-数据持久化
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
ios分享
iPhone,ios,Object-C基础入门
iPhone,ios,Object-c基础入门
旺铺前端设计和实现

Similar to Dropbox sync (7)

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

More from Michael Pan (18)

PDF
Activity
PDF
Shootting Game
PDF
Introduction to Android Studio
PDF
Eclipse and Genymotion
PDF
Note something
PDF
Strategy Pattern for Objective-C
PDF
Core data lightweight_migration
PDF
Google maps SDK for iOS 1.4
PDF
Homework2 play cards
PDF
Prototype by Xcode
PDF
Nimbus
PDF
Superstar dj pdf
KEY
ADB - Arthur
PPTX
比價撿便宜 Steven
KEY
Appsgaga - iOS Game Developer
PPT
GZFox Inc. Jacky
PPT
創投公司 hoku_20121017
KEY
Opening iOS App 開發者交流會
Activity
Shootting Game
Introduction to Android Studio
Eclipse and Genymotion
Note something
Strategy Pattern for Objective-C
Core data lightweight_migration
Google maps SDK for iOS 1.4
Homework2 play cards
Prototype by Xcode
Nimbus
Superstar dj pdf
ADB - Arthur
比價撿便宜 Steven
Appsgaga - iOS Game Developer
GZFox Inc. Jacky
創投公司 hoku_20121017
Opening iOS App 開發者交流會
Ad

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⽇日星期三