【问题标题】:My fileExistsAtPath statement returns false when it should be true我的 fileExistsAtPath 语句在应该为真时返回假
【发布时间】:2016-12-20 22:18:00
【问题描述】:

我正在使用以下代码在我的用户设备上检索收据:

let receiptUrl = NSBundle.mainBundle().appStoreReceiptURL

然后我使用以下方法检查receiptURL 的值是什么:

print("receiptUrl is \(receiptUrl)")

我的控制台将位置显示为:

receiptUrl is Optional(file:///private/var/mobile/Containers/Data/Application/018CF51F-1F55-465B-AA98-B4AD5A864E06/StoreKit/sandboxReceipt)

然后我使用 if 语句:

if NSFileManager.defaultManager().fileExistsAtPath(receiptUrl!.path!)
    { //do great security stuff
    }

但是,我的 fileExistsAtPath 总是返回 false。非常沮丧。

【问题讨论】:

  • 无论我尝试什么,它都会返回 false。

标签: ios swift nsfilemanager file-exists


【解决方案1】:

这可能是正确的结果。 appStoreReceiptURL 不显示存在路径。只需显示商店收据文件夹即可。这个答案相对于this

【讨论】:

  • 感谢杰伊的建议。我看了看,但即使似乎有一个文件,仍然无法将上述内容评估为 true。我认为这可能是文件权限问题。好像我没有打开该特定文件夹的正确权限,但我需要检索收据以进行验证。
  • here 应该是您问题的答案。
猜你喜欢
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 2020-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多