Skip to content

Instantly share code, notes, and snippets.

@jnozzi
Created July 22, 2015 15:56
Show Gist options
  • Save jnozzi/ad9eded5e65ee900eec4 to your computer and use it in GitHub Desktop.
Save jnozzi/ad9eded5e65ee900eec4 to your computer and use it in GitHub Desktop.
A simple test if a mounted volume or device at a given path is a disk image (DMG).
#import <DiskArbitration/DiskArbitration.h>
// ...
- (BOOL)isDMGVolumeAtURL:(NSURL *)url
{
BOOL isDMG = NO;
if (url.isFileURL) {
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
if (session != nil) {
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, (__bridge CFURLRef)url);
if (disk != nil) {
NSDictionary * desc = CFBridgingRelease(DADiskCopyDescription(disk));
NSString * model = desc[(NSString *)kDADiskDescriptionDeviceModelKey];
isDMG = ([model isEqualToString:@"Disk Image"]);
CFRelease(disk);
}
CFRelease(session);
}
}
return isDMG;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment