Ios pjsip接收短信
任何人都知道如何设置pjsip客户端以接收消息的好例子。 我可以使用以下方式从客户端发送消息:Ios pjsip接收短信,ios,sms,message,pjsip,Ios,Sms,Message,Pjsip,任何人都知道如何设置pjsip客户端以接收消息的好例子。 我可以使用以下方式从客户端发送消息: pjsua_im_send(sip_acc_id, &to, NULL, &msgbody, NULL, NULL); 任何数字 但是我不知道如何将消息接收到已经注册的sip帐户中 任何信息都将不胜感激 注意:我只能使用pjsip,不能使用其他库 编辑:我发现了一些新东西: (然而,本文件中关于接收MSG的所有内容如下: 16.1.2接收消息 应用程序将接收任何对话框之外的传入消息
pjsua_im_send(sip_acc_id, &to, NULL, &msgbody, NULL, NULL);
任何数字
但是我不知道如何将消息接收到已经注册的sip帐户中
任何信息都将不胜感激
注意:我只能使用pjsip,不能使用其他库
编辑:我发现了一些新东西:
(然而,本文件中关于接收MSG的所有内容如下:
16.1.2接收消息
应用程序将接收任何对话框之外的传入消息请求
模块。
对话框内的传入消息请求将通过
关于对话框的回调
这对于如何处理传入的消息仍然没有多少启示
Edit2:我被告知此功能需要使用寻呼机功能。因此我尝试了,但不幸的是仍然没有成功
以下是我所做的:
/* 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;
以及寻呼机上的实现:
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);
}
我希望应用程序在收到消息时调用_pager,但它没有。
关于来电
但是,确实有人打电话。结果证明,我所做的是正确的,这只是服务器的问题。
正在接收MSG
总而言之,基本上:
注册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 *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;
}
}