ios – pjsip收到短信

前端之家收集整理的这篇文章主要介绍了ios – pjsip收到短信前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都知道如何设置pjsip客户端来接收消息的任何好例子.
我可以使用以下方式从客户端发送消息:
pjsua_im_send(sip_acc_id,&to,NULL,&msgbody,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()回调对话框.

这仍然没有说明如何处理传入的消息.

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;

和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会被调用.

@H_404_45@

解决方法

事实证明,我所做的是正确的,这只是服务器的一个问题.
接收消息现在正在工作!

总结一下,基本上:

注册sip时:

app_config->cfg.cb.on_pager = &on_pager;

这将注册接收SMS时要调用的on_pager()函数.
其余的由你决定在这个功能内部做什么.

这是函数头:

static void on_pager(pjsua_call_id call_id,const pj_str_t *body)

我认为一切都是自我解释的功能参数等.谢谢大家无论如何尝试!

并且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;
    }
}
@H_404_45@ @H_404_45@

猜你在找的iOS相关文章