C0D*_*0D3 6 sms message pjsip ios
任何人都知道如何设置pjsip客户端来接收消息的任何好例子.我可以使用以下方式从客户端发送消息:
pjsua_im_send(sip_acc_id, &to, NULL, &msgbody, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)
任何数字.
但我不知道如何接收已经注册的SIP帐户的邮件.
任何信息,将不胜感激.
注意:我只能使用pjsip而不能使用其他库.
编辑:我找到的一些新东西:
http://trac.pjsip.org/repos/ticket/1070
http://www.pjsip.org/release/0.5.4/PJSIP-Dev-Guide.pdf(但是所有这些文件都说明传入的消息是这样的:
16.1.2接收消息
应用程序模块将接收任何对话框外的传入MESSAGE请求.对话框内的传入MESSAGE请求将通过对话框的on_tsx_state()回调通知对话框使用情况 .
这仍然没有说明如何处理传入的消息.
http://www.ietf.org/rfc/rfc3261.txt
http://trac.pjsip.org/repos/wiki/SIP_Message_Buffer_Event
Edit2:我被告知on_pager函数需要用于此功能.所以我试过但不幸的是仍然没有成功.
这是我做的:
/* Initialize application callbacks */
app_config->cfg.cb.on_call_state = &on_call_state;
app_config->cfg.cb.on_call_media_state = &on_call_media_state;
app_config->cfg.cb.on_incoming_call = &on_incoming_call;
app_config->cfg.cb.on_reg_state = &on_reg_state;
app_config->cfg.cb.on_pager = &on_pager;
Run Code Online (Sandbox Code Playgroud)
和on_pager实现:
static void on_pager(pjsua_call_id call_id, const pj_str_t *from, const pj_str_t *to, const pj_str_t *contact, const pj_str_t *mime_type, const pj_str_t *body) {
NSLog(@"**************** on_pager called **********************");
AppDelegate *app = (AppDelegate *)[AppDelegate sharedApplication];
pjsua_call_info ci;
pjsua_call_get_info(call_id, &ci);
PJ_UNUSED_ARG(call_id);
PJ_UNUSED_ARG(to);
PJ_UNUSED_ARG(contact);
PJ_UNUSED_ARG(mime_type);
[app ring];
//PJ_LOG(3,(THIS_FILE, "MESSAGE from %.*s: %.*s (%.*s)", (int)from->slen, from->ptr, (int)text->slen, text->ptr, (int)mime_type->slen, mime_type->ptr));
postMessageStateNotification(call_id, &ci);
}
Run Code Online (Sandbox Code Playgroud)
我希望应用程序在收到消息时调用on_pager,但事实并非如此.
on_incoming_call然而,确实被称为.
事实证明,我所做的是正确的,这只是服务器的一个问题.接收消息现在正在工作!
总结一下,基本上:
注册sip时:
app_config->cfg.cb.on_pager = &on_pager;
Run Code Online (Sandbox Code Playgroud)
这将注册接收SMS时要调用的on_pager()函数.其余的由你决定在这个功能内部做什么.
这是函数头:
static void on_pager(pjsua_call_id call_id, const pj_str_t *from, const pj_str_t *to, const pj_str_t *contact, const pj_str_t *mime_type, const pj_str_t *body)
Run Code Online (Sandbox Code Playgroud)
我认为一切都是自我解释的功能参数等.谢谢大家无论如何尝试!
并且app_config在pjsua_init()函数内传递.
此外,在sipStartup()中,我们为iOS注册了NSNotification函数.
/***** SIP ********/
/* */
- (BOOL)sipStartup
{
kSIPCallState = @"CallState";
kSIPRegState = @"RegState";
kSIPMwiInfo = @"MWIInfo";
if (_app_config.pool)
return YES;
self.networkActivityIndicatorVisible = YES;
if (sip_startup(&_app_config) != PJ_SUCCESS)
{
self.networkActivityIndicatorVisible = NO;
return NO;
}
self.networkActivityIndicatorVisible = NO;
CTTelephonyNetworkInfo *phoneInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *phoneCarrier = [phoneInfo subscriberCellularProvider];
NSLog(@"Carrier = %@", phoneCarrier);
[self checkForConnection];
NSTimer *timer;
receiveCallTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
}];
//timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(checkForConnection) userInfo:nil repeats:YES];
/** Call management **/
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processCallState:)
name: kSIPCallState object:nil];
/** Registration management */
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processRegState:)
name: kSIPRegState object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processMessageState:)
name:kSIPMwiInfo object:nil];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
和processMessageState:如下:
- (void)processMessageState:(NSNotification *)notification
{
NSLog(@"***** processMessageState is called *****");
NSNumber *value = [[ notification userInfo] objectForKey:@"CallID"];
pjsua_call_id callId = [value intValue];
int state = [[[ notification userInfo] objectForKey:@"Event"] intValue];
switch (state) {
case PJSIP_EVENT_UNKNOWN:
NSLog(@"unknown event");
break;
case PJSIP_EVENT_TIMER:
NSLog(@"timer event");
break;
case PJSIP_EVENT_RX_MSG:
NSLog(@"received --> rx_msg");
break;
case PJSIP_EVENT_TX_MSG:
NSLog(@"tx_msg");
break;
case PJSIP_EVENT_TRANSPORT_ERROR:
NSLog(@"msg transport error");
break;
case PJSIP_EVENT_TSX_STATE:
NSLog(@"event tsx state");
break;
case PJSIP_EVENT_USER:
NSLog(@"event user");
break;
default:
NSLog(@"processMessageState was called");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1850 次 |
| 最近记录: |