Skip to content

Instantly share code, notes, and snippets.

@jchris
Last active August 29, 2015 14:18
Show Gist options
  • Save jchris/3aa6ae8bc87427ae8dbc to your computer and use it in GitHub Desktop.
Save jchris/3aa6ae8bc87427ae8dbc to your computer and use it in GitHub Desktop.
// 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