Sunday, September 14, 2014

Grabbing call notifications in iOS7

Looks like there is not much in the way of documentation for how to do this so I am going to create one here.

Sometimes people get calls on their phone, I know this is crazy but it can happen. What you should do about it is up to you but how can you let your app know when this happens? Well I can help with that.

in your .h file, add the following.


#import <CoreTelephony/CTCallCenter.h>

@property (nonatomic, strong) CTCallCenter* callCenter;

you need to set the property as if you don't have anything holding on to the connection, it will disappear on your. Gotta love ARC!

in the .m file, here is your master method;

#pragma mark - phone call interrupts
-(void) setupPhoneNotification{
    float static playerVolume;
    self.callCenter = [[CTCallCenter alloc] init];
    self.callCenter.callEventHandler=^(CTCall* call)
    {
        
        if(call.callState == CTCallStateDialing)
        {
            //The call state, before connection is established, when the user initiates the call.
            NSLog(@"Call is dailing");
        }
        if(call.callState == CTCallStateIncoming)
        {
            //The call state, before connection is established, when a call is incoming but not yet answered by the user.
            NSLog(@"Call is Coming");
        }
        
        if(call.callState == CTCallStateConnected)
        {
            //The call state when the call is fully established for all parties involved.
            NSLog(@"Call Connected");
        }
        
        if(call.callState == CTCallStateDisconnected)
        {
            //The call state Ended.
            NSLog(@"Call Ended");
        } 
    };
}

And there you have it. Do whatever you need to do in the block, possibly send a trigger event or notifcation and then you are off to the races. Have fun!

Highjacking a url request via Charles 3.9.2

- install charles
- run what you want that requests data
- copy and edit that information to conform with what you want it to
- save it in a text file (make sure it has no extra stuff like rich text or html headers)
- right click on Charles where the request happened
- choose "map local" which is usually on the bottom of the list
- choose the file you created

From now on, it will use that file instead of what it gets back from the URL request!

Now if you want to add this capability to your devices
- open up your settings
- choose the same wifi as your computer
- go to the bottom of the of wifi setting for that and edit the HTTP PROXY info
- change the "server" to your computer IP and the Port to 8888 (Charles uses this)
- you should get a warning in Charles asking if you want a new device connected to it, say yes
- make sure you have no VPN setup or it may conflict

From now on, your device will also get interrupted by Charles and will get the response that you created instead of the URL response.