如何识别通话后应用程序是否重新加载?

发布于 2024-07-20 18:24:00 字数 241 浏览 8 评论 0原文

我有一个程序,可以在程序启动时自动拨打电话。 这是在 AppDelegate 的“applicationDidFinishLaunching”方法中实现的。

问题是:当电话通话结束并且我的应用程序自动再次启动时,它会重新启动该循环并再次开始电话通话。

如何识别应用程序是否从该调用返回? 或者以某种方式轻松保存定义调用是否已进行的程序的状态或变量?

我刚刚开始 iPhone 编程,就出现了这个问题。

I have a program which automatically launches a phone call when program is started. This is implemented in AppDelegate's "applicationDidFinishLaunching"-method.

Problem is: When phone call ends and my app automatically launches again, it restarts that loop and phone call is started again.

How to recognize if app was returned from that call? Or somehow easily save the state or variables of the program that define if the call was already made?

I just started iPhone programming and this came up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往日 2024-07-27 18:24:01

这是不可能的。 标志的想法很好,直到您意识到并非所有呼叫终止都会返回到应用程序。 例如,如果您按顶部电源按钮挂断电话。

对于这些情况,该标志将不一致(即,下次启动时,您的应用程序会认为这是从调用返回的,而实际上它是从主屏幕启动的)。

总而言之,没有办法检测到手机的返回,我已经向苹果开发人员询问了此事。

This cannot be done. The flag idea is nice until you realize that not all calls termination returns you to the app. One example of this is if you hang up the call by press the top power button.

For those cases, the flag will be inconsistent (ie. upon next launch your app will think that this is returning from a call when in fact it was launched from the home screen).

So to summarize there is no way to detect a return from the phone all and I have asked Apple dev support about this.

长亭外,古道边 2024-07-27 18:24:01

在让您的应用程序启动电话呼叫之前,请阅读 应用程序 NSUserDefaults 数据库,询问是否应该启动该调用,例如 callWasMade

如果 callWasMade 设置为初始默认值 NO,则将标志设置为 YES,并将标志的值保存到 NSUserDefaults code> 然后触发电话呼叫。

在随后启动应用程序时,将从 NSUserDefaults 读取 callWasMade (YES) 的值,并且不会触发调用。

此时,应该可以安全地将标志的值翻转回 NO 以允许下一次调用。

Before having your application launch the phone call, read a BOOL flag in the application NSUserDefaults database that asks whether it should launch that call, e.g. callWasMade.

If callWasMade is set to a initial default of NO, then set the flag to YES, save the flag's value to NSUserDefaults and then trigger the phone call.

On the subsequent launch of your application, the value of callWasMade (YES) is read from NSUserDefaults and the call does not get triggered.

At that point, it should be safe to flip the flag's value back to NO to allow the next call.

没有你我更好 2024-07-27 18:24:01

您可以使用 UIWebview 拨打电话,如本问题中所述:

在本机代码中与 UIWebView 不同的电话呼叫后返回应用程序行为

并使用核心电话检查呼叫是否结束:

//before calling loadRequest:
CTCallCenter *callCenter.callEventHandler=^(CTCall* call) {

        if(call.callState == CTCallStateDialing)
        {
            //The call state, before connection is established, when the user initiates the call.
            NSLog(@"Dialing");
        }
        if(call.callState == CTCallStateIncoming)
        {
            //The call state, before connection is established, when a call is incoming but not yet answered by the user.
            NSLog(@"Incoming Call");
        }

        if(call.callState == CTCallStateConnected)
        {
            //The call state when the call is fully established for all parties involved.
            NSLog(@"Call Connected");
        }   

        if(call.callState == CTCallStateDisconnected)
        {
            [self release];
            NSLog(@"Call Ended");

        }

    };

You can use UIWebview to make a call like explained in this question:

Return to app behavior after phone call different in native code than UIWebView

and use core telephony to check if call ended:

//before calling loadRequest:
CTCallCenter *callCenter.callEventHandler=^(CTCall* call) {

        if(call.callState == CTCallStateDialing)
        {
            //The call state, before connection is established, when the user initiates the call.
            NSLog(@"Dialing");
        }
        if(call.callState == CTCallStateIncoming)
        {
            //The call state, before connection is established, when a call is incoming but not yet answered by the user.
            NSLog(@"Incoming Call");
        }

        if(call.callState == CTCallStateConnected)
        {
            //The call state when the call is fully established for all parties involved.
            NSLog(@"Call Connected");
        }   

        if(call.callState == CTCallStateDisconnected)
        {
            [self release];
            NSLog(@"Call Ended");

        }

    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文