如何解决xpc.h未找到错误?

时间:2014-06-03 11:17:38

标签: ios sms xpc

我正在开发一个iOS应用程序,在这个应用程序中,我在内部发送短信而无需用户参与。谷歌搜索后,我找到了答案,我正在使用此代码。

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);

现在我们将XPC连接myconnection连接到SMS发送服务。但是,XPC配置提供了挂起连接的创建 - 我们需要再激活一步。

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);

连接已激活。此时iOS 6将在电话日志中显示禁止此类通信的消息。现在我们需要生成一个类似于xpc_dictionary的字典,其中包含发送消息所需的数据。

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!");

剩下的很少:将消息发送到XPC端口并确保它已交付。

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

但是为了使用这段代码,我必须添加xpc.h头文件,但是找不到xpc.h头文件。所以,建议我真正需要做的事情。

enter image description here

2 个答案:

答案 0 :(得分:1)

您在iOS中使用XPC,默认情况下标题不会出现在您的身边。我从https://github.com/realthunder/mac-headers获得了/ usr / include - 它包含了xpc.h和相关的头文件。我从中获取了/ xpc子目录并仅将其添加到我的项目中,因为添加完整的/ usr / include会干扰我现有的/ usr / include并导致编译时出现体系结构错误。

即使在添加/ xpc子目录并包含xpc.h之后,由于嵌套的包含问题,我无法使包含路径生效。浪费了大量时间试图获得正确的解决方案,然后使用编辑xpc.h和base.h的kludgy解决方案,以便嵌套的xpc包括不使用任何路径。因此,#include <xpc/base.h>已编辑为#include "base.h"等。

这很有效,应用程序在此之后构建并运行。

答案 1 :(得分:0)

库路径错误地使用了这个...

#include /usr/include/xpc/xpc.h