Last active
August 29, 2015 14:18
-
-
Save jchris/3aa6ae8bc87427ae8dbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Listener | |
func startListener() -> Bool { | |
if listener != nil { | |
return true | |
} | |
var error: NSError? | |
listener = CBLListener(manager: CBLManager.sharedInstance(), port: 0) | |
// Enable Basic Authentication | |
listener.requiresAuth = true | |
let username = secureGenerateKey(NSCharacterSet.URLUserAllowedCharacterSet()) | |
let password = secureGenerateKey(NSCharacterSet.URLPasswordAllowedCharacterSet()) | |
listener.setPasswords([username : password]) | |
var success = listener.start(&error) | |
if success { | |
// Set a sync url with the generated username and password: | |
if let url = NSURL(string: database.name, relativeToURL: listener.URL) { | |
if let urlComp = NSURLComponents(string: url.absoluteString!) { | |
urlComp.user = username | |
urlComp.password = password | |
syncUrl = urlComp.URL | |
} | |
} | |
return true | |
} else { | |
listener = nil | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment