Más contenido relacionado
Similar a Dropbox sync (7)
Dropbox sync
- 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⽇日星期三
- 4. Beware
• Core API & Sync API can not work together
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⽇日星期三
- 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⽇日星期三