简体   繁体   中英

iOS Dropbox API sync, keeps linking account

i want to make my app "dropboxable". So i looked up how to implement the dropbox API correctly. It is a simple txt-File that i want to sync and load in the background. No complex filesystems or whatever. With one simple BarButton i want that the user can connect (the first time) to dropbox and then just sync by pressing the same button. So the first it should link the account to the DBAccountManager and any other time it should just up- and download my files in the background. Here is my Code so far:

- (void)viewDidLoad
{
    [super viewDidLoad];

    DBAccountManager *accountManager = [[DBAccountManager alloc] initWithAppKey:DB_KEY secret:DB_SECRET];

    [DBAccountManager setSharedManager:accountManager];
    self.dbManager = accountManager;
}

- (void)dropboxButtonPressed:(id)sender
{
    DBAccount *account = self.dbManager.linkedAccount;

    if (account.linked) {
        NSLog(@"Already linked!");
    } else {
        NSLog(@"Not linked");

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

It is a really simple solution (i'm a beginner) so the BarButton calls the dropboxButtonPressed method. Oh and i have added a @property (nonatomic, strong) DBAccountManager *dbManager; .

So instead of using the already-linked-path of the if-statement it keeps asking me if i would like to connect with an DropBox Account.

I already downloaded the example projects from DropBox, but as i said i am a beginner and i want it as simple as possible.

Thanks in advance!

You need to have the following code in AppDelegate.m :

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation {
    DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
    if (account) {
        NSLog(@"App linked successfully!");
        return YES;
    }
}

That's assuming you have correctly set up the URL scheme in your <ProjectName>-Info.plist .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM