macOS/iOS API解説

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

目次

descriptorWithDescriptorType:data:

指定したデスクリプタタイプとデータでアップルイベントデスクリプタオブジェクトを返します
+(NSAppleEventDescriptor *)descriptorWithDescriptorType:(DescType)descType:
           data:(NSData *)data:

解説

指定した記述タイプ(descType)とデータでアップルイベントデスクリプタオブジェクトを返します。
【descType】AppleEvent送付先を指定するタイプ
● typeAppleSignature アプリケーションのクリエータタイプ
● typeProcessSerialNumber プロセスのシリアル番号
   {0,kNoProcess}存在しない
   {0,kSystemProcess}システムプロセス
   {0,kCurrentProcess}現在のプロセス
● typeSessionID セッションID
● typeTargetID ターゲットID

返り値

( NSAppleEventDescriptor * )

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

引数

( DescType )descType

デスクリプタタイプ

( NSData * )data

データ

クラス

NSAppleEventDescriptor

Class Methods

使用可能

10.0

参照

例文

#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 descriptorWithDescriptorType:typeProcessSerialNumber data:[restartEvent data]];
    
    NSLog([targetDesc2 description]);

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

@end


//sample2
//シグネチャで送信
OSType creatorType = 'InDn'; //
NSData *typeData = [[NSData alloc] initWithBytes:&creatorType length:sizeof(OSType)];
NSAppleEventDescriptor *targetDescriptor = [NSAppleEventDescriptor descriptorWithDescriptorType:typeApplSignature data:typeData];