我正在使用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,承诺永远不会得到解决。
答案 0 :(得分:1)
AppGyver员工在这里 - 我从您的代码中创建了一个简化的repro,它似乎工作正常。见repro here。
我在处理代码时遇到的一个错误是JSON.stringify(fs)
失败,因为fs
是一个循环结构而JSON.stringify
无法序列化它们。如果只执行console.log(fs)
,则可以很好地获得文件系统对象(您可能需要在Safari Web Inspector中执行location.reload()
以捕获在应用程序加载时发生的事情。)