use*_*716 4 avfoundation ios parse-platform swift
根据上面的代码,我正在创建一个sound.caf在已知文件路径位置调用的音频文件soundfileURL.
我的问题是如何将此文件上传到Parse?如何从路径中获取代码中的文件对象soundfileURL.
我在下面的尝试显然需要工作.我没有运行它,因为我不知道如何转换sound.caf为PFFile并上传到Parse.
func addNamestoParse(obj: Music) {
println("Doing Parse Stuff now")
self.showActivityIndicatory(true)
var className = PFObject(className: "musicrecording")
className.setObject(obj.name, forKey: "nameofmusic")
className.setObject(obj.createdOn, forKey: "datcreated")
Run Code Online (Sandbox Code Playgroud)
如何转换SOUND.CAF文件来支持这里并上传游戏?
className.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if success == true {
} else {
println(error)
}
}
}
Run Code Online (Sandbox Code Playgroud)
感谢David Jirman的Objective-C等价能够推断出Swift Equivalent.下面是代码.
func addNamestoParse(obj: Name) {
println("Doing Parse Stuff now")
var className = PFObject(className: "namerecordings")
className.setObject(obj.name, forKey: "babyname")
className.setObject(obj.nameSubmitter, forKey: "submittedby")
className.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if success == true {
let audioFile = PFFile(name: "mysound.caf", data: NSData(contentsOfURL: self.soundFileURL)!)
className["audioFile"] = audioFile
className.saveInBackgroundWithBlock{(success: Bool, error: NSError?) -> Void in
if success == false {
println("error in uploading audio file")
} else {
println("posted successfully")
}
}
} else {
println(error)
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
在https://www.youtube.com/watch?v=4qj1piMAPE0这个很棒的教程之后,我的解决方案是在Swift中:
let path = getCacheDirectory().stringByAppendingPathComponent(fileName)
let filePath = NSURL(fileURLWithPath: path)
var dataToUpload : NSData = NSData(contentsOfURL: filePath!)!
let soundFile = PFFile(name: fileName, data: dataToUpload)
var userSound = PFObject(className:"upload")
userSound["name"] = "Sara"
userSound["sound"] = soundFile
userSound.saveInBackground()
Run Code Online (Sandbox Code Playgroud)
其中getCacheDirectory()是本教程中使用的函数
| 归档时间: |
|
| 查看次数: |
2923 次 |
| 最近记录: |