如何在Objective C中列出连接到Mac的设备并获取它们的/dev/tty?
我非常希望为我过去一天左右构建的应用程序做到这一点。
我需要列出连接到Mac的设备,并找到一个符合我的应用程序标准的设备。如何找到这些设备,并将它们的/dev/tty作为NSStrings列在列表中?
如何在Objective C中列出连接到Mac的设备并获取它们的/dev/tty?
我非常希望为我过去一天左右构建的应用程序做到这一点。
我需要列出连接到Mac的设备,并找到一个符合我的应用程序标准的设备。如何找到这些设备,并将它们的/dev/tty作为NSStrings列在列表中?
头文件 Mounter.h
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
@interface Mounter : NSObject {
struct statfs *buf;
int i, count;
@private
}
-(void) getMountList;
@end
Mounter.m 文件的实现:
#import "Mounter.h"
@implementation Mounter
-(void) getMountList {
NSFileManager *fm = [NSFileManager defaultManager];
count = getmntinfo(&buf, 0);
for (i=0; i<count; i++)
{
NSString *path = [NSString stringWithUTF8String:buf[i].f_mntonname];
NSLog(@"Drivers: %@", path);
}