我正在使用pjsip开发一个用于I-phone的voip应用程序作为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);
答案 0 :(得分:3)
我终于回答了我的问题。
我提出了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);
答案 1 :(得分:0)
不是Objective-c的专家。一些基础知识
始终在for循环之前初始化 pjsua_msg_data_init(&msg_data);
而不是在循环中
将 pjsip_generic_string_hdr subject;
更改为对象数组