macOS/iOS API解説

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

目次

initWithDescriptorType:data:

デスクリプタタイプで指定されるオブジェクトを指定したデータで初期化して返します
-(id)initWithDescriptorType:(DescType)descType:
           data:(NSData *)data:

解説

デスクリプタタイプ(descType)で指定されるオブジェクトを指定したデータ(data)で初期化して返します。エラーが発生すればnilを返します。
【descType】AppleEvent送付先を指定するタイプ
● typeAppleSignature アプリケーションのクリエータタイプ
● typeProcessSerialNumber プロセスのシリアル番号
   {0,kNoProcess}存在しない
   {0,kSystemProcess}システムプロセス
   {0,kCurrentProcess}現在のプロセス
● typeSessionID セッションID
● typeTargetID ターゲットID

返り値

( id )

アップルイベントデスクリプタ

引数

( DescType )descType

デスクリプタタイプ

( NSData * )data

データ

クラス

NSAppleEventDescriptor

Instance Methods

使用可能

10.0

参照

+ descriptorWIthDescriptorType:data:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
RequestSystemRestart();

}

//リスタートする
static BOOL RequestSystemRestart()
{
    OSStatus status = noErr;
    const ProcessSerialNumber systemPsn = { 0, kSystemProcess };//アプリのプロセスナンバー
    NSData *data;
   
    
    //ターゲットを作る
    NSAppleEventDescriptor* targetDesc = [NSAppleEventDescriptor
        descriptorWithDescriptorType: typeProcessSerialNumber
        bytes: &systemPsn
        length: sizeof(systemPsn)
    ];
    //イベントを作る
    NSAppleEventDescriptor* restartEvent = [[NSAppleEventDescriptor alloc]
        initWithEventClass: kCoreEventClass
        eventID: kAEShutDown//
        targetDescriptor: targetDesc
        returnID: kAutoGenerateReturnID
        transactionID: kAnyTransactionID
    ];

    
    NSAppleEventDescriptor* targetDesc2 = [[NSAppleEventDescriptor alloc] initWithDescriptorType:typeProcessSerialNumber data:[restartEvent data]];
    
    NSLog([targetDesc2 description]);

    //AppleEvent送信
    /*
    status = AESendMessage(
        (const AppleEvent*)[restartEvent aeDesc],
        NULL,
        kAENoReply | kAECanSwitchLayer | kAEAlwaysInteract,
        kAEDefaultTimeout
    );
*/
    return (status == noErr);
}

@end