.NET, Mobile, Xamarin

Xamarin.iOS – Dropbox API v2 integration tips

Xamarin.iOS is not very popular platform. As shows Dropbox, for their API v2 they even do not provide even good SDK (in .NET, only for web based). If we consider any mobile development in Xamarin, the best examples which I found were dedicated to Windows Phone 8.1 and Xamarin.Android, so completly different approach. For iOS there is available SDK for Swift. Xamarin is fully omitted in login process. Fortunatelly operations on files like upload works correctly. The challenge: get OAuth token.

The only one option is web based API which redirects user from one site to another. It is very uncomfortable for mobile developers as that requires using embedded browser window like WKWebView (btw I found that UIWebView is obsolete). Easy and well described part is creating login request.

It has to contain redirect_uri parameter (not empty) to which the response (with token) will be redirected. Unfortunately it cannot be app URI but it has to start from http/https (enforced by Dropbox page when it has to be specified).

The question is how to handle successful response? WKWebView class contains NavigationDelegate property of type WKNavigationDelegate. After inheriting from that class, the method DidReceiveServerRedirectForProvisionalNavigation has to be overriden. Just be careful! There is multiple redirects, and the correct one has to be filtered (the parameter start from #access_token e.g. http://mydomain/#access_token). The redirect response contains multiple parameters so the right one has to be selected.

And that is it! Now just DropboxClient(<token>) and it works 🙂

PS. There is dedicated solution for Xamarin (multi storage facade) but it is commercial one.

Leave a Reply

Your email address will not be published.