Xcode 是否有针对iCloud磁盘容量和使用情况的API?
我使用NSFileManager获取当前设备磁盘空间(总空间、已用空间和可用空间),如下所示Xcode 是否有针对iCloud磁盘容量和使用情况的API?,xcode,icloud,nsfilemanager,ios9,cloudkit,Xcode,Icloud,Nsfilemanager,Ios9,Cloudkit,我使用NSFileManager获取当前设备磁盘空间(总空间、已用空间和可用空间),如下所示 let systemAttributes = try? NSFileManager.defaultManager().attributesOfFileSystemForPath(NSHomeDirectory() as String) let space = (systemAttributes?[NSFileSystemSize] as? NSNumber)?.longLongValue 有没
let systemAttributes = try? NSFileManager.defaultManager().attributesOfFileSystemForPath(NSHomeDirectory() as String)
let space = (systemAttributes?[NSFileSystemSize] as? NSNumber)?.longLongValue
有没有办法为用户的iCloud帐户做类似的事情?我希望能够在应用程序中显示用户的iCloud磁盘空间统计信息。Capacity
iCloud在线容量由苹果公司决定。本地缓存大小由磁盘上的限制设置。我先前的回答提到了磁盘容量。您的样本应返回您自己设备的大小
文档大小
下面的答案已被修改,以帮助您确定iCloud容器路径的文件大小。还有其他方法,比如枚举子路径,这可能是您想要的。我在下面介绍最简单的应该可以工作的东西(我还没有测试过)。如果你在寻找不同的东西,请告诉我
根据苹果和Xcode中的快速帮助,您可能希望查看URLForUbiquityContainerIdentifier
返回与指定对象关联的iCloud容器的URL
标识符并建立对该容器的访问。指向
指定的ubiquity容器,如果无法创建该容器,则为nil
位于或当前用户无法使用iCloud存储;或
装置
关于使用此属性的重要注意事项:
根据这些信息,类似的东西可能会起作用……请务必检查文档、快速帮助和头文件,以了解任何其他注意事项
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), { () -> Void in
//Note: The container identifier is in your Capabilities > iCloud > Containers
if let iCloudPath = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier("iCloud.com.yourcompanydomain.app")?.path {
let pathAttributes = try? NSFileManager.defaultManager().attributesOfItemAtPath(iCloudPath)
let space = (pathAttributes?[NSFileSize] as? NSNumber)?.unsignedLongLongValue
dispatch_async(dispatch_get_main_queue()) {
print ("iCloud disk space: \(space)")
}
}
})
对不起,等了这么久。虽然这在技术上是可行的,但它返回的是本地磁盘的大小,而不是云容器的大小。如果我找到合适的解决方案,我会更新这篇文章。@WDyson~我根据你的评论做了几处修改。希望这能帮你解决问题。