xcode iOS 中的后台应用程序,可检测来电

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10891503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:30:07  来源:igfitidea点击:

background app in iOS that detects incoming phone calls

iphoneobjective-cxcodeios4

提问by revolutionary

I need to write a background application in iOS which listens to incoming phone calls on the iPhone.

我需要在 iOS 中编写一个后台应用程序来监听 iPhone 上的来电。

Is it possible? Can anyone suggest some good pointers ?

是否可以?任何人都可以提出一些好的建议吗?

Thankyou

谢谢

回答by Michael Dautermann

This would be very much against Apple's privacy policy and there's no chance an app like this would be approved.

这将非常违反 Apple 的隐私政策,而且这样的应用程序不可能获得批准。

There are call recording apps that sneakaround this restriction, though, but they use third party services and no actual built-in iPhone API's.

不过,有一些通话录音应用程序可以绕过此限制,但它们使用第三方服务并且没有实际内置的 iPhone API。

回答by emesefabian

You can do it in applicationWillEnterForeground using CTCallCenter's CTCallState properties. Don't forget to import the CoreTelephony framework. Here's an example:

您可以使用 CTCallCenter 的 CTCallState 属性在 applicationWillEnterForeground 中执行此操作。不要忘记导入 CoreTelephony 框架。下面是一个例子:

#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [callCenter setCallEventHandler:^(CTCall *call) {
        if ([[call callState] isEqual:CTCallStateIncoming] || [[call callState] isEqual:CTCallStateDialing]) {

            if ([viewController isPlaying])
            {
                NSLog(@"Call was started.");
            }
        } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
            if (callWasStarted)
            {
               NSLog(@"Call was ended.");
            }
        }
    }];
}