Skip to content

Commit

Permalink
[TaskyDrop] port sample to use Dropbox Datastore API
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed Jul 11, 2013
1 parent 3fc7d7a commit bb5d51f
Show file tree
Hide file tree
Showing 61 changed files with 2,483 additions and 31 deletions.
26 changes: 5 additions & 21 deletions Azure/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
TaskyAzure for iOS & Android
Dropbox Datastore API (with Xamarin.iOS)
============================
There are a number of sample projects using the same Azure Mobile Services instance:
This sample has a very basic implementation of Dropbox's new (Jul-2013) Datastore API in a To Do list application.

* iOS with MonoTouch
![screenshot](https://raw.github.com/conceptdev/TaskCloud/master/Dropbox/Screenshots/iOS1.png)

* Android for Mono for Android
Use the [Dropbox Datastore API](https://www.dropbox.com/developers/datastore) to learn about the service, create new application keys and read the documentation.

* Windows Phone 7

* Mac-OSX with MonoMac

* Windows 8 sample provided by Microsoft


![screenshot](https://raw.github.com/conceptdev/TaskCloud/master/Azure/Screenshots/Screenshots_sml.png)

This sample has a very basic implementation of Microsoft's new (Sep-2012) Azure Mobile Services API.

It is loosely based on this article (ie the syntax for the REST requests)
[chrisrisner.com/Windows-Azure-Mobile-Services-and-](http://chrisrisner.com/Windows-Azure-Mobile-Services-and-iOS) however the Mono-for-Android application code is based on the existing Tasky samples (and uses MonoTouch.Dialog).

The Windows Phone 7 version uses the 'unofficial' [Azure Mobile Services Client](https://github.com/kenegozi/azure-mobile-csharp-sdk}

Use the [Azure Getting Started](https://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started/) code to first set-up the Windows 8 sample app. The iOS, Android and Windows 8 apps will then read/write to the same TodoList !
Check out [Xamarin's blog post](http://blog.xamarin.com/a-quick-look-at-dropbox%E2%80%99s-new-datastore-api%E2%80%A6-in-c-sharp/) for information on the Xamarin Component.
Binary file added DropBox/Screenshots/iOS1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions DropBox/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;


using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.ObjCRuntime;
using DropBoxSync.iOS;

namespace TaskyDrop
{
/// <summary>Kick everything off</summary>
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args, null, "AppDelegate");
}
}

[Register ("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
const string DropboxSyncKey = "YOUR_APP_ID";
const string DropboxSyncSecret = "YOUR_APP_SECRET";

UINavigationController navController;

UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{

UINavigationBar.Appearance.TintColor = UIColor.FromRGB (29, 131, 219);

window = new UIWindow (UIScreen.MainScreen.Bounds);
window.BackgroundColor = UIColor.White;
window.Bounds = UIScreen.MainScreen.Bounds;

var u = new TaskListScreen();
navController = new UINavigationController();
navController.PushViewController (u, false);

window.RootViewController = navController;
window.MakeKeyAndVisible ();




// DROPBOX STUFF
// The account manager stores all the account info. Create this when your app launches
var manager = new DBAccountManager (DropboxSyncKey, DropboxSyncSecret);
DBAccountManager.SharedManager = manager;

var account = manager.LinkedAccount;
if (account != null) {
SetupDropbox ();
} else
manager.LinkFromController (window.RootViewController);
//--


return true;
}

public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
var account = DBAccountManager.SharedManager.HandleOpenURL (url);
SetupDropbox ();
return account != null;
}

void SetupDropbox ()
{
System.Threading.Tasks.Task.Factory.StartNew (() => {
DropboxDatabase.Shared.Init ();
});
}
}
}
1 change: 1 addition & 0 deletions DropBox/iOS/Components/dropboxsync-1.9.info

Large diffs are not rendered by default.

Binary file added DropBox/iOS/Components/dropboxsync-1.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions DropBox/iOS/Components/dropboxsync-1.9/component/Details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
The Dropbox Sync API allows you to give your app its own private Dropbox client and leave the syncing to Dropbox.

- Focus on your data. The Sync API handles all the caching, retrying, and file change notifications.
- Writes are local so changes are immediate. The Sync API syncs to Dropbox behind the scenes.
- Your app works great even when offline and automatically syncs when it's back online.

### Datastore API (beta)

Keep your app's structured data in sync with Dropbox. These days, your app need to store and sync more than just files. With the Datastore API, structured data like contacts, to-do items, and game state can be synced effortlessly. Datastores work across platforms, offline, and even support automatic conflict resolution.

## Authenticating with Dropbox

Add the following lines of code to link a user's Dropbox account to your
app:

### In AppDelegate.cs

```csharp
using DropBoxSync.iOS;
...

// Get your own App Key and Secret from https://www.dropbox.com/developers/apps
const string DropboxSyncKey = "YOUR_APP_KEY";
const string DropboxSyncSecret = "YOUR_APP_SECRET";

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{

// The account manager stores all the account info. Create this when your app launches
var manager = new DBAccountManager (DropboxSyncKey, DropboxSyncSecret);
DBAccountManager.SharedManager = manager;

var account = manager.LinkedAccount;
if (account != null) {
var filesystem = new DBFilesystem (account);
DBFilesystem.SharedFilesystem = filesystem;
}

// ...
}

public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
var account = DBAccountManager.SharedManager.HandleOpenURL (url);
if (account != null) {
var filesystem = new DBFilesystem (account);
DBFilesystem.SharedFilesystem = filesystem;
Console.WriteLine ("App linked successfully!");
return true;
} else {
Console.WriteLine ("App is not linked");
return false;
}
}

```

### In Info.plist

You'll need to register the url scheme "db-DropboxSyncKey" to complete the
authentication flow. Double-click on your app's Info.plist file, select
the Advanced Tab, find the URL Types Section, then click Add URL Type
and set URL Schemes to db-DropboxSyncKey (i.e. "db-aaa111bbb2222").

### Link the user

Once you've added the code above, you're ready to link the user's
Dropbox account from your UI. For example, add this snippet to a UI
event handler in one of your controllers:

```csharp
DBAccountManager.SharedManager.LinkFromController (myController)
```

This will show the Dropbox OAuth screen and ask the user to link their
account.
Loading

0 comments on commit bb5d51f

Please sign in to comment.