3

I am new to the jailbreak tweak development scene. I am trying to figure out the appropriate method to 'hook' so I can intercept an incoming call (and then run some code).

I have dumped the header files of CoreTelephony framework however no methods seem obvious to hook. I have tried:

- (void)broadcastCallStateChangesIfNeededWithFailureLogMessage:(id)arg1;
- (BOOL)setUpServerConnection;

but neither have worked. By worked I mean - get called when the iPhone receives a call.

Any pointers as to the appropriate method to hook? Thanks :)

Note: This is going to be a jailbreak tweak using private APIs so it won't be submitted to the App Store.

3
  • Do you just need to get notified when a phone call comes in, or do you need to truly intercept the call that normally goes to the Phone app, so that you can replace some of the code that normally runs? Let me know if the difference is not clear, as I've described it.
    – Nate
    Feb 7, 2013 at 21:58
  • It would work just being notified. I have since gone down this route using [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil]; but the "callReceived" method is not being called (ironic). I'll have a play around, it's probably something obvious! Feb 7, 2013 at 22:28
  • What do you need that for?
    – AlexWien
    Feb 8, 2013 at 3:56

2 Answers 2

2

I didn't test your code, but I think your problem might be that you need to use the Core Telephony notification center to register for that event (not what you had in the code in your comment). Something like this:

// register for all Core Telephony notifications
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct,   // center
                             NULL, // observer
                             telephonyEventCallback,  // callback
                             NULL,                    // event name (or all)
                             NULL,                    // object
                             CFNotificationSuspensionBehaviorDeliverImmediately);

and your callback function is

static void telephonyEventCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
    NSString *notifyname = (NSString*)name;
    if ([notifyname isEqualToString:@"kCTCallIdentificationChangeNotification"])
    {
        NSDictionary* info = (NSDictionary*)userInfo;
        CTCall* call = (CTCall*)[info objectForKey:@"kCTCall"];
        NSString* caller = CTCallCopyAddress(NULL, call);

        if (call.callState == CTCallStateDisconnected)
        {
            NSLog(@"Call has been disconnected");
        }
        else if (call.callState == CTCallStateConnected)
        {
            NSLog(@"Call has just been connected");
        }
        else if (call.callState == CTCallStateIncoming)
        {
            NSLog(@"Call is incoming");
        }
        else if (call.callState == CTCallStateDialing)
        {
            NSLog(@"Call is Dialing");
        }
        else
        {
            NSLog(@"None of the conditions");
        }
    }
}

I offer another technique in this similar question here. Also, note my comment in that question about not getting the notifications in a UIApplication that has been put into the background.

Update: see cud_programmer's comment below about using kCTCallStatus on iOS 6 instead of kCTCall.

15
  • 1
    @cud_programmer, so if you really don't need to perform UI operations, then it seems to me to make even more sense to build a Launch Daemon, that runs all the time. Then, you don't have to worry about all the restrictions iOS puts on normal UIApplications. The link to my other answer has a link to Chris Alvares' online tutorial for creating launch daemons.
    – Nate
    Feb 9, 2013 at 0:06
  • 1
    I'm using [[[info objectForKey:@"kCTCallStatus"] stringValue] isEqualToString:@"4"] and it works. call.callState still crashes the program. Feb 23, 2013 at 23:02
  • 1
    @nanospeck, unfortunately, CTCallCenterAddObserver() is not a public API, so that would probably get this rejected. However, CTCall is public. So, there must now be some API that allows you to use it.
    – Nate
    Oct 15, 2014 at 10:14
  • 1
  • 1
    @nanospeck, if the docs used the word "suspended" specifically, make sure you understand the different iOS app states clearly. If you're wanting an app that can always get notified and never suspends, there's a few ways to achieve that, but they probably wouldn't be accepted on the App Store.
    – Nate
    Oct 15, 2014 at 10:52
0

Is it possible?

Yes.

Would a regular average person with no background in computer engineering or knowhow of how cell towers work be capable of something like this?

No.

Technically you can buy router looking thing to do this which aren’t cheap, are illegal and cellphone companies can actually track them down since it interferes with the network. So other than government agencies or international spies i don’t think you have anything to worry about. But if the government is exactly what you’re worried about well I’m sorry to tell you they’ve been doing a lot more then intercepting just phones

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.