ios - 无法为我的 iOS VoIP 应用程序显示 onComingCall ViewController
<p><p>我希望我的应用在收到来电时显示 IncomingCall ViewController。</p>
<p>这是我用来显示来电的代码。来 self 的 ContactsViewController,它是来电时的 Active View。</p>
<pre><code>- (void)showIncomigCallVC{
;
}
</code></pre>
<p>这是我的代码,由库调用。</p>
<pre><code> /* Callback called by the library upon receiving incoming call */
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata)
{
pjsua_call_info ci;
PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "....\n\n\n Incoming call from %.*s!!\n\n\n",
(int)ci.remote_info.slen,
ci.remote_info.ptr));
ContactsViewController *incomingCallVC = [init];
;
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, NULL, NULL);
}
</code></pre>
<p>这是我的控制台输出:</p>
<pre><code>20:39:37.482 XCPjsua.c......
Incoming call from <sip:[email protected]>!!
2017-01-16 20:39:37.494 simpleVoIP *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ContactsViewController: 0x7bea3d00>) hasno segue with identifier 'segueToIncomingCallVC''
*** First throw call stack:
(
0 CoreFoundation 0x03a14212 __exceptionPreprocess + 194
1 libobjc.A.dylib 0x034d3e66 objc_exception_throw + 52
2 UIKit 0x01a69893 - + 0
3 simpleVoIP 0x00089ba6 - + 70
4 simpleVoIP 0x00086caf on_incoming_call + 255
5 simpleVoIP 0x000fc273 pjsua_call_on_incoming + 3811
6 simpleVoIP 0x00103294 mod_pjsua_on_rx_request + 84
7 simpleVoIP 0x0012938f pjsip_endpt_process_rx_data + 351
8 simpleVoIP 0x00128bf2 endpt_on_rx_msg + 546
9 simpleVoIP 0x0012fba1 pjsip_tpmgr_receive_packet + 849
10simpleVoIP 0x001315ec udp_on_read_complete + 316
11simpleVoIP 0x0014b8e0 ioqueue_dispatch_read_event + 704
12simpleVoIP 0x0014d5b2 pj_ioqueue_poll + 946
13simpleVoIP 0x001290c3 pjsip_endpt_handle_events2 + 163
14simpleVoIP 0x00102023 worker_thread + 99
15simpleVoIP 0x0014eb96 thread_main + 86
16libsystem_pthread.dylib 0x04c8a11b _pthread_body + 184
17libsystem_pthread.dylib 0x04c8a063 _pthread_body + 0
18libsystem_pthread.dylib 0x04c8993e thread_start + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException
</code></pre>
<p>我是初学者,任何建议将不胜感激.. 提前致谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您正在经历崩溃,因为您正在以编程方式分配您的 <code>ContactsViewController</code>,而不是从 <code>storyboard</code> 使用。</p>
<p>当你这样做时:</p>
<pre><code> ContactsViewController *incomingCallVC = [init];
;
</code></pre>
<p>您正在创建一个 <code>ContactsViewController</code> 的实例,这与我们在 <code>storyboard</code> 中创建的实例无关。<br/>
有可能克服这个问题,但是,您正在尝试对 <code>viewController</code> 进行 <code>segue</code> 调用,该调用仅被加载到内存中,但不可见一点也不。这永远不会奏效,它总是会崩溃。</p>
<p>我建议立即显示您的 <code>viewController</code>,无论是在 segue 后面的什么,而不是创建一个 <code>viewController</code> 并用 segue 显示它。</p>
<p><strong>编辑</strong>:</p>
<p>使用下面的代码,您应该能够从回调函数的末尾呈现您想要的 <code>UIViewController</code> 子类。</p>
<pre><code>// Lets get keywindow
UIWindow* keyWindow = [[ delegate] window];
keyWindow.frame = .bounds;
// Lets get `IncomingCallViewController` from storyboard
UIStoryboard *sb = ;
// do not forget to set the identifier of your viewController on the storyboard as "IncomingCallViewController"
UIViewController *vc = ;
// Lets present the keyWindow from the main thread
dispatch_async(dispatch_get_main_queue(), ^{
keyWindow.rootViewController = vc;
;
});
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法为我的 iOS VoIP 应用程序显示 onComingCall ViewController,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41680317/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41680317/
</a>
</p>
页:
[1]