我正在寻找一种更好的方法来以编程方式检测iPhone/iPad设备上的可用/可用磁盘空间.
目前我正在使用NSFileManager来检测磁盘空间.以下是为我完成工作的代码片段:
-(unsigned)getFreeDiskspacePrivate {
NSDictionary *atDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/" error:NULL];
unsigned freeSpace = [[atDict objectForKey:NSFileSystemFreeSize] unsignedIntValue];
NSLog(@"%s - Free Diskspace: %u bytes - %u MiB", __PRETTY_FUNCTION__, freeSpace, (freeSpace/1024)/1024);
return freeSpace;
}
我是否正确使用上述代码段?或者有更好的方法来了解总可用/可用磁盘空间.
我要检测总可用磁盘空间,因为我们要阻止我们的应用程序在低磁盘空间场景中执行同步.
我一直在尝试添加一些代码来在键盘出现时移动我的视图,但是,我在尝试将Objective-C示例转换为Swift时遇到了问题.我取得了一些进展,但我被困在一条特定的路线上.
这些是我一直关注的两个教程/问题:
当Keypad使用Swift出现时,如何向上移动UIViewController的内容 http://www.ioscreator.com/tutorials/move-view-when-keyboard-appears
这是我目前的代码:
override func viewWillAppear(animated: Bool) {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
    NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardWillShow(notification: NSNotification) {
    var keyboardSize = notification.userInfo(valueForKey(UIKeyboardFrameBeginUserInfoKey))
    UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
    let frame = self.budgetEntryView.frame
    frame.origin.y = frame.origin.y - keyboardSize
    self.budgetEntryView.frame = frame
}
func keyboardWillHide(notification: NSNotification) {
    //
}
目前,我在这一行收到错误:
var keyboardSize = notification.userInfo(valueForKey(UIKeyboardFrameBeginUserInfoKey))
如果有人能让我知道这行代码应该是什么,我应该设法自己弄清楚其余部分.
我正在按照苹果记录的示例来了解如何查询我的设备上的可用磁盘空间。
我在我的中使用下面的代码applicationDidFinishLaunchingWithOptions:
let fileURL = URL(fileURLWithPath:"/")
do {
    let values = try fileURL.resourceValues(forKeys: [
        .volumeAvailableCapacityKey,
        .volumeAvailableCapacityForImportantUsageKey,
        .volumeAvailableCapacityForOpportunisticUsageKey,
        .volumeTotalCapacityKey
    ])
    print("Available Capacity: \(Float(values.volumeAvailableCapacity!)/1000000000)GB")
    print("ImportantUsage Capacity: \(Float(values.volumeAvailableCapacityForImportantUsage!)/1000000000)GB")
    print("Opportunistic Capacity: \(Float(values.volumeAvailableCapacityForOpportunisticUsage!)/1000000000)GB")
    print("Total Capacity: \(Float(values.volumeTotalCapacity!)/1000000000)GB")
} catch {
    print("Error retrieving capacity: \(error.localizedDescription)")
}
这会记录以下内容:
Available Capacity: 3.665879GB
ImportantUsage Capacity: 0.0GB
Opportunistic Capacity: 0.0GB
Total Capacity: 63.989494GB
为什么volumeAvailableCapacityForImportantUsage和volumeAvailableCapacityForOpportunisticUsage为零以及在什么情况下会发生这种情况?
背景:
注意:这与这个问题 …