HMDT - Logic and Intuition -

about HMDT

Cocoa Programming Tips 1001

With I/O Kit

Power Management

With I/O Kit - Power Management

Macをスリープさせる

Keywords: IOPMSleepSysmte

Macをスリープさせたいときは、Cocoaだけじゃ無理なので、I/O KitのPower Managementを使う。IOPMSleepSystem()というAPIを呼んでやればいい。

IOKit/IOPMLib.h

IOReturn IOPMSleepSystem(io_connect_t fb);

使い方はこんな感じ。

SleepTest/AppController.m

- (IBAction)sleepAction:(id)sender
{
    // Get mach port
    mach_port_t masterPort;
    if (IOMasterPort(bootstrap_port, &masterPort) != kIOReturnSuccess) {
        NSLog(@"Failed to get master port");
        return;
    }
    
    // Find powet management
    io_connect_t    powManage;
    powManage = IOPMFindPowerManagement(masterPort);
    if (!powManage) {
        NSLog(@"Failed to find power management");
        return;
    }
    
    // Go to sleep
    if (IOPMSleepSystem(powManage) != kIOReturnSuccess) {
        NSLog(@"Failed to sleep");
        return;
    }
}

■サンプルダウンロード:
SleepTest.zip

back to top content

Copyright © 2002-2006 HMDT. All rights reserved.