6

で簡単なサンプル アプリを試してXPCServicesいます。以下の手順に従っています。

ステップ 1:サンプル プロジェクトを作成し、XPCServices名前付きでターゲットを追加HelperProcessしました。ターゲットが作成されると、XCode は以下のファイルを自動的に生成します。

  1. HelperProcessProtocol.h
  2. HelperProcess.h
  3. HelperProcess.m
  4. main.m

ステップ 2:main.m実装内にログ ステートメントを追加しました。ServiceDelegate

- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
    // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
    NSLog(@"Log which is never displayed :(");
    // Configure the connection.
    // First, set the interface that the exported object implements.
    newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];

    // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
    HelperProcess *exportedObject = [HelperProcess new];
    newConnection.exportedObject = exportedObject;

    // Resuming the connection allows the system to deliver more incoming messages.
    [newConnection resume];

    // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
    return YES;
}

ステップ 3:以下AppDelegateのコードを追加applicationDidFinishLaunching:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application

    _connectionToService = [[NSXPCConnection alloc] initWithServiceName:@"HelperProcess"];
    _connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];
    [_connectionToService resume];
}

問題は -

アプリを起動すると、listener:shouldAcceptNewConnection: に追加されたログが表示されず、Activity Monitor にヘルパー プロセスが表示されません:(

コードは次のとおりです。

注: XCode 6.0でこれを試しています

動作させるために必要な追加のセットアップはありますか? 提案してください。

- アップデート -

Appleからこのサンプルを参照しようとしました: AppSandboxLoginItemXPCDemo

XCode 6 で実行しようとすると、「署名 ID が見つかりません」というエラー メッセージが表示されました。Mac 開発者アカウントを登録していないため、iDecide と iDecideHelper のビルド設定で、「コード署名 ID」を「コード署名しない」に変更しました。

ターゲットごとに警告が表示されました。

Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.

今回ビルドをコンパイルしたところ、期待どおりに動作しました。

ここで、ReadMe.txt ファイルで指定された手順に従おうとしました。具体的には、サンプル アプリで次の手順を実行しました。

ステップ 1:更新 - メイン アプリ ターゲット -> [機能] タブ

  1. 「アプリサンドボックス」をオンにしました
  2. 「アプリ グループ」をオンにしました
  3. アプリ グループ「XYZ」を追加しました

ステップ 2:更新 - ヘルパー ターゲット -> [機能] タブ

  1. 「アプリサンドボックス」をオンにしました
  2. 「発信接続 (クライアント)」を有効にしました
  3. 「アプリ グループ」をオンにしました
  4. アプリ グループ「XYZ」を追加しました

ステップ 3:更新 - ヘルパー ターゲット -> [全般] タブ -> [バンドル識別子] に「XYZ」プレフィックスを追加しました。

コンソールでアプリを実行すると、次のメッセージが表示されました。

10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.

10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013  { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." }  (handleMessage()/appleEventsD.cp #2072) client-reqs-q

listener:shouldAcceptNewConnection:アプリは意図した機能を実行せず、デリゲートに追加されたログ メッセージを表示しませんでした。

私は無知です。不足しているものがあれば教えてください。Mac 開発者アカウントを登録せずに、XPC サービス サンプル アプリを動作させることはできますか?

4

1 に答える 1