15

I would like to be able to selectively block incoming calls in an iOS application I'm writing. This is intended for personal use, not the App Store, so I'm fine with using private APIs to accomplish this.

I have recently come across the Core Telephony framework. Is there a way to use this framework to block calls? If not, what private APIs could I use to do this?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

3 Answers3

36

Are you sure it does not? code examples on http://tech.ruimaninfo.com/?p=83 shows how to do such things. Core Telephony headers in SDK are not complete. Of course this means no app store this is my code fragment based on example I linked

if ([str1 isEqualToString:@"kCTCallIdentificationChangeNotification"])
{
    NSDictionary *info = (__bridge NSDictionary *)userInfo;
    CTCall2 *call = (__bridge CTCall *)[info objectForKey:@"kCTCall"];
    NSString *caller = CTCallCopyAddress(NULL, call);
    NSLog(@"Caller %@",caller);
    if ([caller isEqualToString:@"+1555665753"])
    {
       //disconnect this call
       CTCallDisconnect(call);

}

additional definitions needed:

typedef struct __CTCall CTCall;
extern NSString *CTCallCopyAddress(void*, CTCall *);
extern void CTCallDisconnect(CTCall*);

and you need to monitor telephony center's callback(see linked example) I tested this fragment on my iOS5 device

Tauri
  • 1,291
  • 1
  • 14
  • 28
  • I no I can't put it in on the App Store but how would I block a specific number using that link? – SimplyKiwi Dec 01 '11 at 12:32
  • Not yet, I don't see any changes :/ – SimplyKiwi Dec 03 '11 at 06:41
  • Niceeee. I honestly think you get at least 10 up votes over the next few months since that code is very helpful! One last thing, how would I keep the app running so that, that code you posted is called whenever I get a call even if the app is closed? – SimplyKiwi Dec 03 '11 at 07:00
  • strictly speaking you can't - apple rules. but looking at http://stackoverflow.com/questions/4656214/iphone-backgrounding-to-poll-for-events and http://stackoverflow.com/questions/7610182/is-it-legal-to-create-a-recursive-background-handler-in-iphoneprocessing-when can give you some ideas. one thing I encountered - you better keep CoreLocation active and not in SignificantLocationMonitoring mode(even with 3km accuracy) or you could be terminated too fast. Of course you must measure battery usage issues(after all you use CoreLocation),etc – Tauri Dec 03 '11 at 07:03
  • you sure? I know iBlacklist and MCaller do it that way but they have the phone JB'ed. Are you positive that there is no way? – SimplyKiwi Dec 03 '11 at 07:04
  • enter pressed too fast. see my edited comment. there is way, but tricky(you have to play by apple rules here) – Tauri Dec 03 '11 at 07:07
  • If it doesn't then I want to know how is this 360安全卫士 app doing it? check it guys – Asadullah Ali Jun 29 '15 at 07:57
  • itunes link to 360 app please – Tauri Jun 29 '15 at 12:42
  • Does anybody have any urls of code source example as the web site http://tech.ruimaninfo.com/?p=83 isn't responding. I want to be able to determine the incoming number – Gruntcakes Mar 25 '16 at 18:46
3

Core Telephony doesn't support this. To my knowledge there is no way to do this with any known private APIs either.

Greg Martin
  • 5,074
  • 3
  • 34
  • 35
2

Since iOS 10.0+ there is CallKit which includes a Call Blocking and Identification API: https://developer.apple.com/documentation/callkit

(Information for people which find this in 2020 or in the future)

C. D. Miksche
  • 88
  • 1
  • 7