EXC_BAD_INSTRUCTION при отправке сообщения в службу XPC - PullRequest
2 голосов
/ 13 декабря 2011

Я пытаюсь использовать службу XPC для межпроцессного взаимодействия.Я добавил цель службы XPC в свой проект, а затем, когда я пытаюсь выполнить xpc_connection_send_message, я получаю EXC_BAD_INSTRUCTION.Насколько я могу судить, я правильно инициализирую и запускаю соединение.

serviceConnection = xpc_connection_create("com.foo.bar.MyService", dispatch_get_main_queue());

xpc_connection_set_event_handler(serviceConnection, ^(xpc_object_t event) {
    xpc_type_t type = xpc_get_type(event);

    if (type == XPC_TYPE_ERROR) {
        if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
            // The service has either cancaled itself, crashed, or been
            // terminated.  The XPC connection is still valid and sending a
            // message to it will re-launch the service.  If the service is
            // state-full, this is the time to initialize the new service.
        } 

        else if (event == XPC_ERROR_CONNECTION_INVALID) {            
            // The service is invalid. Either the service name supplied to
            // xpc_connection_create() is incorrect or we (this process) have
            // canceled the service; we can do any cleanup of appliation
            // state at this point.
            NSLog(@"Uh oh, connection invalid");
            xpc_release(serviceConnection);
            serviceConnection = nil;
            //xpc_release(stack);
            //stack = NULL;
        } 

        else {
            NSLog(@"Unknown XPC error.");
        }
    } 
});

xpc_connection_resume(serviceConnection);

и затем отправляю сообщение

xpc_object_t message = xpc_data_create(NULL, 0);
....
xpc_connection_send_message(serviceConnection, message);

Чего-то мне здесь не хватает?Неужели не удается найти и подключиться к услуге?

...