         ]
         return components.URL!
     }
-    
-    private func dAuthURL(nonce: String?) -> NSURL {
+
+    private func dAuthScheme() -> String? {
+        if canOpenDAuthScheme("dbapi-2") {
+            return "dbapi-2"
+        } else if canOpenDAuthScheme("dbapi-8-emm") {
+            return "dbapi-8-emm"
+        } else {
+            return nil
+        }
+    }
+
+    private func canOpenDAuthScheme(scheme: String) -> Bool {
+        return UIApplication.sharedApplication().canOpenURL(dAuthURL(scheme, nonce: nil))
+    }
+
+    private func dAuthURL(scheme: String, nonce: String?) -> NSURL {
         let components = NSURLComponents()
-        components.scheme =  "dbapi-2"
+        components.scheme =  scheme
         components.host = "1"
         components.path = "/connect"
         

            controller.presentViewController(alertController, animated: true, completion: { fatalError(message) } )
            return
        }
        if UIApplication.sharedApplication().canOpenURL(dAuthURL(nil)) {
            let nonce = NSUUID().UUIDString
            NSUserDefaults.standardUserDefaults().setObject(nonce, forKey: kDBLinkNonce)
            NSUserDefaults.standardUserDefaults().synchronize()
            
            UIApplication.sharedApplication().openURL(dAuthURL(nonce))
        } else {
            let web = DropboxConnectController(
                URL: self.authURL(),

    private func hasApplicationQueriesScheme() -> Bool {
        
        let queriesSchemes = NSBundle.mainBundle().objectForInfoDictionaryKey("LSApplicationQueriesSchemes") as? [String] ?? []

        var countSchemes = 0
        for scheme in queriesSchemes {
            if scheme == "dbapi-2" {
                countSchemes++
            } else if scheme == "dbapi-8-emm" {
                countSchemes++
            }
            if countSchemes >= 2 {
                return true
            }
        }
