pjsip接收短信
任何人都知道如何设置一个pjsip客户端接收消息的好例子。 我可以使用以下方式从客户端发送消息:
pjsua_im_send(sip_acc_id, &to, NULL, &msgbody, NULL, NULL);
到任何数字。
但我不知道该怎么做,以接收消息到已注册的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()callback被通知给对话使用。
这对于如何处理传入的消息仍然没有多大亮点。
http://www.ietf.org/rfc/rfc3261.txt
http://trac.pjsip.org/repos/wiki/SIP_Message_Buffer_Event
编辑2:我已经被告知on_pager函数需要用于这个function。 所以我尝试,但不幸的是仍然没有成功。
这是我做的:
/* 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;
和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); }
我希望应用程序在收到消息时调用on_pager,但是没有。 on_incoming_call
然而,确实被调用。
原来,我所做的是正确的,这只是服务器的一个问题。 接收消息正在工作!
总结起来,基本上是:
当注册sip时:
app_config->cfg.cb.on_pager = &on_pager;
这将注册接收SMS的on_pager()函数。 其余的由你来决定该function的内容。
这是function标题:
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)
我认为一切都是自我解释的function参数,等谢谢大家试试!
并且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; }
和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; } }