2012-09-19 10 views
6

누구나 메시지를 수신하도록 pjsip 클라이언트를 설정하는 방법에 대한 좋은 예를 알고 계실 것입니다. 나는 사용하여 클라이언트에서 메시지를 보낼 수 있습니다pjsip 수신 SMS

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 (그러나이 모든 문서가이가 들어오는 MSG를에 대해 말한다 : MESSAGE

받기

16.1.2

대화 상자 외부에서 수신되는 메시지 요청은 응용 프로그램에 의해 수신됩니다. 모듈. 대화 상자에서 들어오는 MESSAGE 요청은 on_tsx_state() 대화 상자의 콜백을 통해 대화 상자 사용으로 통보됩니다.

수신 메시지를 처리하는 방법에 대해서는 아직 밝혀지지 않았습니다.

http://trac.pjsip.org/repos/wiki/SIP_Message_Buffer_Event

Edit2가

http://www.ietf.org/rfc/rfc3261.txt :가 나는 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이 호출됩니다.

답변

6

내가 한 일은 정확했으며 서버와 관련된 문제 일뿐입니다. msgs 수신 중입니다.

기본적 요약하면 :

위해 SIP 가입 다음 on_pager() 함수를 등록한다

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

는 SMS를 수신 할 때 호출된다. 나머지는 그 기능 안에서 무엇을 할 것인가에 달려 있습니다.

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) 

나는 등, 모든 함수 매개 변수에 대한 설명 자체라고 생각합니다 감사합니다 모두 어쨌든 시도에 대한 :

이 함수 헤더입니다!

그리고 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; 
    } 
}