1

我正在使用 pjsip 作为 sip 堆栈为 I-phone 开发 voip 应用程序,我想添加自定义标头可以添加,但只添加了一个,我卡住了,我不明白出了什么问题,下面是我的代码片段

pj_status_t status = PJ_SUCCESS;
    pj_str_t pj_uri;

    pjsua_msg_data msg_data;
    pjsip_generic_string_hdr subject;
    pj_str_t hvalue, hname;

    pj_uri = pj_str((char *)uri);


    for(NSString *key in [headers allKeys]){

        NSLog(@"Call.m key value in call %@,%@",key,[headers objectForKey:key] );

        pjsua_msg_data_init(&msg_data);

        hname = pj_str((char *)[key UTF8String]);

        char * headerValue=(char *)[(NSString *)[headers objectForKey:key] UTF8String];

        hvalue = pj_str(headerValue);


        pjsip_generic_string_hdr_init2 (&subject, &hname, &hvalue);
        pj_list_push_back(&msg_data.hdr_list, &subject);

    }


    status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);
4

2 回答 2

4

我再次回答了我赢得的问题。

生病提出的代码 wrks

pj_caching_pool cp;
  pj_pool_t *pool;
  pj_status_t status = PJ_SUCCESS;
  pj_str_t pj_uri;

  pjsua_msg_data msg_data;
  pjsua_msg_data_init(&msg_data);


  pj_uri = pj_str((char *)uri);


  pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
  pool= pj_pool_create(&cp.factory, "header", 1000, 1000, NULL);

  for(NSString *key in [headers allKeys]){

    NSLog(@"Call.m key value in call %@,%@",key,[headers objectForKey:key] );
    pj_str_t hname = pj_str((char *)[key UTF8String]);
    char * headerValue=(char *)[(NSString *)[headers objectForKey:key] UTF8String];
    pj_str_t hvalue = pj_str(headerValue);
    pjsip_generic_string_hdr* add_hdr = pjsip_generic_string_hdr_create(pool, &hname, &hvalue);
    pj_list_push_back(&msg_data.hdr_list, add_hdr);
  }
  status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, &msg_data, call_id);
  pj_pool_release(pool);
于 2013-09-20T14:14:54.527 回答
0

不是objective-c的专家。一些基础知识

始终pjsua_msg_data_init(&msg_data);在 for 循环之前而不是在循环中初始化

更改pjsip_generic_string_hdr subject;为对象数组

于 2013-09-17T21:12:20.487 回答