使用$ FirebaseObject时,有没有办法进行多位置更新?
当我这样尝试时,我收到错误" Firebase.update失败:第一个参数在属性中包含无效键($ id)"
var customerData = {};
customerData["Customers/" + user.uid] = firebaseObject;
customerData["ProjectOverview/" + user.uid] = "value";
ref.update(customerData);
我可以使用this SO question中的解决方案,但这似乎不是最好的方法。
使用$ FirebaseObject时,有更好的方法来进行多位置更新吗?
答案 0 :(得分:1)
您可以$firebaseUtils.toJSON()
使用var customerData = {};
customerData["Customers/" + user.uid] = $firebaseUtils.toJSON(firebaseObject);
customerData["ProjectOverview/" + user.uid] = "value";
ref.update(customerData);
:
var listening = false
var transaction: SKTransaction?
var session: SKSession?
override func viewDidLoad() {
super.viewDidLoad()
session = SKSession(URL: NSURL(string: serverURL), appToken: appKey)
let audioFormat = SKPCMFormat()
audioFormat.sampleFormat = .SignedLinear16;
audioFormat.sampleRate = 16000;
audioFormat.channels = 1;
print("\(NSHomeDirectory())/start.mp3")
// Attach them to the session
session!.startEarcon = SKAudioFile(URL: NSURL(fileURLWithPath: "\(NSHomeDirectory())/start.mp3"), pcmFormat: audioFormat)
session!.endEarcon = SKAudioFile(URL: NSURL(fileURLWithPath: "\(NSHomeDirectory())/stop.mp3"), pcmFormat: audioFormat)
}
@IBAction func speechButtonDidClick(sender: AnyObject) {
if listening == false {
transaction = session?.recognizeWithType(SKTransactionSpeechTypeDictation,
detection: .Short,
language: "eng-USA",
delegate: self)
}else{
transaction?.stopRecording()
}
}
// SKTransactionDelegate
func transactionDidBeginRecording(transaction: SKTransaction!) {
messageText.text = "listening"
listening = true
indicator.startAnimating()
startPollingVolume()
}
func transactionDidFinishRecording(transaction: SKTransaction!) {
messageText.text = "stopped"
listening = false
indicator.stopAnimating()
stopPollingVolume()
}
func transaction(transaction: SKTransaction!, didReceiveRecognition recognition: SKRecognition!) {
print("got something")
//Take the best result
if recognition.text != nil{
speechTextField.text = recognition.text
}
}
func transaction(transaction: SKTransaction!, didReceiveServiceResponse response: [NSObject : AnyObject]!) {
print ("service response")
print(response)
}
func transaction(transaction: SKTransaction!, didFinishWithSuggestion suggestion: String!) {
}
func transaction(transaction: SKTransaction!, didFailWithError error: NSError!, suggestion: String!) {
print ("error")
print(error)
}
var timer = NSTimer()
var interval = 0.01;
func startPollingVolume() {
timer = NSTimer.scheduledTimerWithTimeInterval(interval,
target: self,
selector: #selector(ViewController.pollVolume),
userInfo: nil,
repeats: true)
}
func pollVolume() {
if transaction != nil{
let volumeLevel:Float = transaction!.audioLevel
audioLevelIndicator.progress = volumeLevel / 90
}
}
func stopPollingVolume() {
timer.invalidate()
audioLevelIndicator.progress = 0
}