在 Cocoa 中查找插入的 CD 的名称
我有一个书签,其中描述了如何执行此操作的过程 - 在 OS X 中查找已安装 CD 的名称 - 但当我重新格式化我的 Mac 时,我删除了该书签。 :P
阅读这个主题,我认为这可能有效。基本上,我需要在继续应用程序
- 访问 NSWorkspace
- 之前验证是否已安装特定 CD执行“checkForRemovableMedia”
- 从“mountedRemoveableMedia”获取已安装媒体路径数组
- 运行已安装媒体路径数组以查找包含目标光盘名称的路径
无论如何,这就是我想出的一个可能的解决方案。还有人在 Cocoa 这方面有任何其他想法/知识吗?建议:)
编辑: 我在下面编写了这段代码,但不起作用。它创建了一个包含 NSCFStrings 的 NSCFArray,我读了它,但不应该这样做。
NSArray *mountedItems = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
int count = [mountedItems count];
int i = 0;
for (i = 0; i < count; i++) {
//line is not printing. contains NSCFArray and NSCFStrings
[NSLog print:[[mountedItems objectAtIndex:i] stringValue]];
}
I had a bookmark which described the process on how to do this - finding the name of a mounted CD in OS X - but I deleted the bookmark when I reformatted my Mac. :P
Reading up on the subject, this is what I think might work. Basically, I need to verify if a particular CD is mounted before continuing in the application
- Access NSWorkspace
- Perform 'checkForRemovableMedia'
- Grab array of mounted media paths from 'mountedRemoveableMedia'
- Run through array of mounted media paths to find one containing name of targeted disc
Anyway, this is what I've came up with as a possible solution. Anyone else have any other ideas/knowledge in this area in Cocoa? Suggestions :)
EDIT:
I made this code below, but isn't working. It creates an NSCFArray which contains NSCFStrings, which I read up and shouldn't be doing.
NSArray *mountedItems = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
int count = [mountedItems count];
int i = 0;
for (i = 0; i < count; i++) {
//line is not printing. contains NSCFArray and NSCFStrings
[NSLog print:[[mountedItems objectAtIndex:i] stringValue]];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,所以我是个白痴。
我不仅错误地使用了 NSLog,而且完全没有意识到也许在字符串上调用“stringValue”是多余的。以及导致代码损坏的原因。 :P
现在可以了;我还添加了“checkForRemovableMedia”作为额外的预防措施。
OK, so I'm an idiot.
I was not only using NSLog wrong, but completely didn't even realize that perhaps calling 'stringValue' on a string is redundant. And also what caused the code to break. :P
This works now; I also added 'checkForRemovableMedia' as an extra precaution.