简体   繁体   English

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

[英]background app in iOS that detects incoming phone calls

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 谢谢

This would be very much against Apple's privacy policy and there's no chance an app like this would be approved. 这将非常违反苹果的隐私政策,而且这样的应用程序也不会被批准。

There are call recording apps that sneak around this restriction, though , but they use third party services and no actual built-in iPhone API's. 尽管 有一些通话记录应用程序 绕过了这个限制,但是它们使用第三方服务,而没有实际的内置iPhone API。

You can do it in applicationWillEnterForeground using CTCallCenter's CTCallState properties. 您可以使用CTCallCenter的CTCallState属性在applicationWillEnterForeground中进行操作。 Don't forget to import the CoreTelephony framework. 不要忘记导入CoreTelephony框架。 Here's an example: 这是一个例子:

#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.");
            }
        }
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM