ajeet sharma
ajeet sharma

Reputation: 843

How to resolve xpc.h not found error?

I am working on a iOS application and in this application I have send SMS internally without user involvement. And After googling I found a answer and I am using this code.

xpc_connection_t myconnection;

dispatch_queue_t queue = dispatch_queue_create("com.apple.chatkit.clientcomposeserver.xpc", DISPATCH_QUEUE_CONCURRENT);

myconnection = xpc_connection_create_mach_service("com.apple.chatkit.clientcomposeserver.xpc", queue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);

Now we have the XPC connection myconnection to the service of SMS sending. However, XPC configuration provides for creation of suspended connections —we need to take one more step for the activation.

xpc_connection_set_event_handler(myconnection, ^(xpc_object_t event){
xpc_type_t xtype = xpc_get_type(event);
if(XPC_TYPE_ERROR == xtype)
{
NSLog(@"XPC sandbox connection error: %s\n", xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
}
// Always set an event handler. More on this later.

NSLog(@"Received an message event!");

});

xpc_connection_resume(myconnection);

The connection is activated. Right at this moment iOS 6 will display a message in the telephone log that this type of communication is forbidden. Now we need to generate a dictionary similar to xpc_dictionary with the data required for the message sending.

NSArray *receipements = [NSArray arrayWithObjects:@"+7 (90*) 000-00-00", nil];

NSData *ser_rec = [NSPropertyListSerialization dataWithPropertyList:receipements format:200 options:0 error:NULL];

xpc_object_t mydict = xpc_dictionary_create(0, 0, 0);
xpc_dictionary_set_int64(mydict, "message-type", 0);
xpc_dictionary_set_data(mydict, "recipients", [ser_rec bytes], [ser_rec length]);
xpc_dictionary_set_string(mydict, "text", "hello from your application!");

Little is left: send the message to the XPC port and make sure it is delivered.

xpc_connection_send_message(myconnection, mydict);
xpc_connection_send_barrier(myconnection, ^{
NSLog(@"Message has been successfully delievered");
});

But for using this code I have to add xpc.h header file, but xpc.h header is not found. So, suggest what actually I need to do.

enter image description here

Upvotes: 3

Views: 3732

Answers (1)

RealHandy
RealHandy

Reputation: 602

You're using XPC in iOS, and the headers aren't going to be there for you by default. I got the /usr/include from https://github.com/realthunder/mac-headers -- it includes the xpc.h and related headers. I took the /xpc subdirectory from that and added only it to my project, because adding the full /usr/include interfered with my existing /usr/include and caused an architecture error on compile.

Even after adding the /xpc subdirectory and including xpc.h, I was unable to get the include paths to work due to nested include problems. Wasted lots of time trying to get the proper solution, then used the kludgy solution of editing xpc.h and base.h so that the nested xpc includes didn't use any path. So, #include <xpc/base.h> was edited to #include "base.h", etc.

That worked, the app builds and runs after that.

Upvotes: 2

Related Questions