PjSip添加多个标题

我正在开发一个VoIP电话使用pjsip的SIP应用程序作为SIP堆栈,我想添加自定义头可以添加,但只有一个被添加,卡住我不忍受什么是错的,下面是我的代码片段

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

我再次回答我的问题。

我把那个代码写出来了

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

不是Objective-C的专家。 一些基础知识

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

改变pjsip_generic_string_hdr subject; 到一个对象数组