1

SMJobSubmitXcodeで作成したUnix実行可能ファイルを通常のデスクトップアプリ内から起動するために使用しようとしています。(GUI部分は、コマンドラインヘルパーツールを呼び出すことになっています。)

これが私が仕事を提出しようとするのに使うコードです。

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [authView setString:kSMRightModifySystemDaemons];
    [authView setAutoupdate:YES];
    [authView setDelegate:self];
}

- (IBAction)pressedButton:(id)sender
{
    /*
      authView is an instance of SFAuthorizationView. At this point, the user
      already clicked the padlock and entered his password.
    */
    authRef = [[authView authorization] authorizationRef];

    //toolPath points to the file in the app's Resource folder.
    NSArray* call = [NSArray arrayWithObject:toolPath];

    NSDictionary* jobSpec = [NSDictionary dictionaryWithObjectsAndKeys:
                             call, @"ProgramArguments",
                             jobLabel, @"Label",
                             [NSNumber numberWithBool:YES], @"RunAtLoad",
                             nil];

    CFErrorRef submitError = nil;
    BOOL submitResult = SMJobSubmit(kSMDomainSystemLaunchd,
                                    (__bridge CFDictionaryRef)(jobSpec),
                                    authRef,
                                    &submitError);

    if(!submitResult)
    {
        NSLog(@"Job submit failed. %@", submitError);
        return;
    }
}   

submitResult常にであることが判明しましたがtrue、私のプログラムは実行されていないようです。ターミナルから手動でプログラムを実行しましたが、完全に機能します。ヘルパーツールは、ファイルシステム上の場所にファイルを書き込むことになっており、引数を取りません。ただし、デーモンを起動するために送信しても、何も起こりません。実行可能としてマークされています。パスも確認しました。あたりです。

では、launchデーモンが特定の種類のファイルしか実行できないのではないかと疑問に思っています。コードで何かを台無しにしない限り。

4

1 に答える 1

0

作成した承認参照にはkSMRightModifySystemDaemons、launchd を使用して実行可能ファイルを実行できる権限が必要です。

を使用することにより、

[authview SetAuthorizationRights:kSMRightModifySystemDaemons]

の前の発言

authRef = [[authView authorization] authorizationRef];

物事はうまくいくはずです。<ServiceManagement/ServiceManagement.h>の定義に含める必要がある場合がありますkSMRightModifySystemDaemons

于 2012-09-26T12:40:47.050 に答える