3

私は iOS アプリケーションに取り組んでおり、このアプリケーションでは、ユーザーの関与なしに SMS を内部的に送信しています。グーグルで調べた後、答えが見つかり、このコードを使用しています。

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

これで、SMS 送信サービスへの XPC 接続 myconnection ができました。ただし、XPC 構成では、中断された接続を作成できます。アクティブ化するには、もう 1 つの手順を実行する必要があります。

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 ヘッダーが見つかりません。だから、私が実際に何をする必要があるかを提案してください。

ここに画像の説明を入力

4

2 に答える 2

-1

ライブラリパスは間違ってこれを使用しています...

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

于 2014-09-27T21:29:41.100 に答える