macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

unmountAndEjectDeviceAtPath:

INDEX>AppKit>NSWorkspace

パスでアンマウントして、デバイスを排出します

Objective-C

- (BOOL)unmountAndEjectDeviceAtPath:(NSString *)path

Swift

func unmountAndEjectDeviceAtPath(_ path: String) -> Bool

解説

パスでアンマウントして、デバイスを排出します。
このメソッドが開始するとき、それはNSWorkspaceの通知センターにNSWorkspaceWillUnmountNotificationを掲示する。
それが終わるとき、それはNSWorkspaceDidUnmountNotificationを掲示する。

返り値

アンマウントされたかYES/NO
Objective-C

BOOL

Swift

Bool

引数

アンマウントするデバイスのパス

Objective-C

(NSString *)path

Swift

_ path: String

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.0

参照

更新時のバージョン

OS X 10.10.3
Swift1.2


例文

//ディスクをマウント解除するので不必要なディスクイメージなどでテストしてください

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{

 //開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];

    //OpenPanelの結果のボタン番号
    int		  opRet;
    BOOL	openResult;
     [opPanel setCanChooseDirectories:YES];
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : @"/" //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : fileTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
    
        openResult = [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath:[ opPanel filename ] ];

    }

}

@end

Swift

    //NSWorkspace unmountAndEjectDeviceAtPath
    func buttonAction033(sender: AnyObject){
        
        let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace()

        let result : Bool  = theWorkspace.unmountAndEjectDeviceAtPath("/Volumes/ディスクイメージ")
        if result {
            NSLog("OK")
        }else{
            NSLog("NG")
        }
        
    }