How to list devices connected to Mac's USB ports?
How do I list the devices connected to the mac and get their /dev/tty things in Objective C?
I would really love to do this for an application that I've been building for the past day or so.
I need to list the devices connected to the mac, and find one that will suit my criteria for this application. How do I find the devices, and list the开发者_JS百科ir /dev/tty's as NSStrings in a list?
Finding and Accessing Devices will get you additional information.
The header file 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
The implementation Mounter.m file:
#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);
}
精彩评论