From 72d30fbd466b95971f6dae51e9b0fb2a86f217a1 Mon Sep 17 00:00:00 2001 From: Stephen Cobbe Date: Tue, 16 May 2017 21:14:13 -0700 Subject: [PATCH] Updated README to include instructions to force app to foreground. --- README.md | 8 ++++++-- .../TestObjectiveDropbox_macOS/AppDelegate.m | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbb8dd22e..d0f3d2478 100644 --- a/README.md +++ b/README.md @@ -277,10 +277,11 @@ After you've made the above changes, your application's `.plist` file should loo ### Handling the authorization flow -There are two methods to programmatically retrieve an OAuth 2.0 access token: +There are three methods to programmatically retrieve an OAuth 2.0 access token: * **Direct auth** (iOS only): This launches the official Dropbox iOS app (if installed), authenticates via the official app, then redirects back into the SDK -* **Safari view controller auth** (iOS, macOS): This launches a `SFSafariViewController` to facillitate the auth flow. This is desirable because it is safer for the end-user, and pre-existing session data can be used to avoid requiring the user to re-enter their Dropbox credentials. +* **Safari view controller auth** (iOS only): This launches a `SFSafariViewController` to facillitate the auth flow. This is desirable because it is safer for the end-user, and pre-existing session data can be used to avoid requiring the user to re-enter their Dropbox credentials. +* **Redirect to external browser** (macOS only): This launches the user's default browser to facillitate the auth flow. This is also desirable because it is safer for the end-user, and pre-existing session data can be used to avoid requiring the user to re-enter their Dropbox credentials. To facilitate the above authorization flows, you should take the following steps: @@ -403,6 +404,9 @@ To handle the redirection back into the Objective-C SDK once the authentication } else if ([authResult isError]) { NSLog(@"Error: %@", authResult); } + // this forces your app to the foreground, after it has handled the browser redirect + [[NSRunningApplication currentApplication] + activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]; } } ``` diff --git a/TestObjectiveDropbox/TestObjectiveDropbox_macOS/AppDelegate.m b/TestObjectiveDropbox/TestObjectiveDropbox_macOS/AppDelegate.m index 623f7aeff..dfd42e87f 100644 --- a/TestObjectiveDropbox/TestObjectiveDropbox_macOS/AppDelegate.m +++ b/TestObjectiveDropbox/TestObjectiveDropbox_macOS/AppDelegate.m @@ -117,6 +117,8 @@ - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSApple } } [self checkButtons]; + [[NSRunningApplication currentApplication] + activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]; } - (void)checkButtons {