0

我正在使用 appgyver 类固醇(phonegap)并尝试将照片从相机 API 保存到应用程序文件空间,以便在我重新扫描/重新加载应用程序时不会将其删除。我正在关注cordova api docs(http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileSystem)中的示例,但我从未收到过回复

window.requestileSystem(LocalFileSystem.PERSISTENT, ...)

承诺永远不会被解决/拒绝。我究竟做错了什么?

# in coffeescript
console.log "1. window.deviceReady. navigator.camera"+JSON.stringify(navigator.camera), null, 10000
_fsDeferred = $q.defer()
window.requestFileSystem(
  LocalFileSystem.PERSISTENT, 
  50000*1024, 
  (fs)-> 
    console.log "2. window.requestFileSystem, FS= "+JSON.stringify(fs), null, 10000
    _fsRoot = fs.root
    _fsDeferred.resolve(_fsRoot)
  (ev)->
    console.log "3. Error: requestFileSystem failed. "+ev.target.error.code, 'danger', 10000
    _fsDeferred.reject(ev)
)
_fsDeferred.promise.finally ()-> 
  console.log "4. window.requestFileSystem(), Deferred.promise.finally(), args"+JSON.stringify arguments, 'danger', 10000

我从来没有到达#4,承诺永远不会解决。

4

1 回答 1

1

AppGyver 员工在这里——我从你的代码中创建了一个简化的重现,它似乎工作正常。在这里查看重现。

我在处理您的代码时遇到的一个错误JSON.stringify(fs)是失败,因为fs它是一个循环结构并且JSON.stringify无法序列化它们。如果你只是这样做console.log(fs),你会得到文件系统对象(你可能需要location.reload()在 Safari Web Inspector 中做一个来捕捉应用程序加载时发生的事情)。

于 2014-04-03T08:45:56.397 回答