Help for using Calls Notification API using Core Telephony framework

Discussion in 'iOS Development' started by amitchauhan, Jul 2, 2009.

  1. amitchauhan

    amitchauhan New Member

    Joined:
    Jun 23, 2009
    Messages:
    24
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Dear All,

    Could you please help me for the below mentioned queries.

    I am using the Open ToolChain SDk to develop the Toolchain based application for Jailbreaked iPhone.

    Please help me for the following queries.
    1) How can i always active my toolchain Application.(like Background process).
    2) When the incomming call & SMS how can i get that
    and what method will be invoke.
    3) And I am not able to use the UIAlertView it gives me the lot of error message. if i import the <UIKit/UIAlert.h>.
    4) I need to Supressed that incomming call and SMS as well, if i am in roaming.



    I am using the below line of code:
    Code:
    static void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
    {
    	
    	//CallValue=[[NSString alloc]retain];
    	//CallValue=[NSString stringWithFormat:@"%d",25];
    	
    	if (userInfo)
    		// CFShow(userInfo);
    	{
    		
    		NSDictionary *info = userInfo;
    		int dcount = CFDictionaryGetCount(userInfo);
    		id keys = [userInfo allKeys];
    		//CallValue=[NSString stringWithFormat:@"%d",25];
    		//NSLog(@"%@",CallValue);
    		
    	}
    	return;
    }
    static void signalHandler(int sigraised)
    {
        printf("\nInterrupted.\n");
        _exit(0);
    }
    void usage(char *appname)
    {
        printf("%s : options \n", appname);
        printf("-s     listen to standard notifications\n");
        printf("-t     listen to core telephony notifications\n");
    }
    int main(int argc, char **argv)
    {
    	int returnCode;
    	 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	 returnCode = UIApplicationMain(argc, argv, @"BTApp", @"BTApp");
    	
    	 //return returnCode;
    	//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    	
        if (argc < 2) {usage(argv[0]); exit(0);}
    	
        NSString *readNotifications = @"NOTSTRING";
        NSArray *notifications = [readNotifications componentsSeparatedByString:@"BOUNDARY"];
    	
    
        opterr = 0;
        int c;
    	// id results;
        BOOL isTelephony = NO;
        BOOL isStandard = NO;
    	
        while ((c = getopt (argc, argv, "ts")) != -1)
    		switch (c)
    	{
            case 's': 
                isStandard = YES;
    			break;
            case 't': 
                isTelephony = YES;
                break;
            case '?':
    			if (isprint (optopt))
    				fprintf (stderr, "Unknown option `-%c'.\n", optopt);
    			else
    				fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
    		default:
    			return 0;
    	}
    	if ((!isStandard) && (!isTelephony))
        {
            printf("Listen either to standard (-s), telephony (-t) notifications or both\n");
            printf("No notification type selected. Exiting.\n");
            exit(-1);
        }
    	
        if (isStandard)
        {
            printf("Watching for Standard Notifications (%d notifications)\n", [notifications count]);
    		
            for (id *notification in notifications)
            {
                CFNotificationCenterAddObserver(
    											CFNotificationCenterGetDarwinNotifyCenter(), //center
    											NULL, // observer
    											callback, // callback
    											notification, // name
    											NULL, // object
    											CFNotificationSuspensionBehaviorHold
    											); 
            }
        }
    	
        if (isTelephony)
        {
    		printf("Watching for Core Telephony notifications\n");
            id ct = CTTelephonyCenterGetDefault();
            CTTelephonyCenterAddObserver(
    									 ct, 
    									 NULL, 
    									 callback,
    									 NULL,
    									 NULL,
    									 CFNotificationSuspensionBehaviorHold);
        }
    	
        // Set up a signal handler so we can clean up when we're interrupted from the command line
        sig_t oldHandler = signal(SIGINT, signalHandler);
        if (oldHandler == SIG_ERR) {
            printf("Could not establish new signal handler");
            exit(1);
        }
    	
        // Start the run loop. Now we'll receive notifications.
        printf("Starting Notification Scan. ^C to quit.\n");
        CFRunLoopRun();
    	
        printf("Unexpectedly back from CFRunLoopRun()!\n");
    	[pool release];
    	
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)notification {	
    	// Create window
    	
    	window = [[UIWindow alloc] initWithContentRect: [UIHardware fullScreenApplicationContentRect]];
      
    	// Set up content view
    	CGRect rect=[UIHardware fullScreenApplicationContentRect];
    	rect.origin.x=rect.origin.y=0.0f;
    	
    	mainView = [[MainView alloc] initWithFrame: rect];
    	//[mainView setBackgroundColor:[UIColor redColor]];
    	
    	[window setContentView: mainView];
        [window makeKey:self];
    	// Show window
    	[window orderFront:self];
    	[window makeKeyAndVisible];
    	[window _setHidden:NO];
    }
    - (void)dealloc {
    	//[mainView release];
    	[window release];
    	[super dealloc];
    }
    @end
    
    @implementation MainView
    
    -(id)initWithFrame:(CGRect)rect
    {
    	self=[super initWithFrame:rect];
    	if(nil!=self)
    	{
    		
    		/*id ct = CTTelephonyCenterGetDefault();
    		 
    		CTTelephonyCenterAddObserver(ct, NULL, callback,NULL, NULL, CFNotificationSuspensionBehaviorHold);
    		/////////////////
    		//NSNumber *pdate = (NSNumber*)CFPreferencesCopyAppValue(CFSTR("RecentsLastViewedDate"),
    															  //CFSTR("com.apple.mobilephone"));
    		
    		//NSDate *aDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: [pdate doubleValue]];
    		
    	    //int ct = _CTCallHistoryStoreGetCountOfMissedCallSince(aDate);
    		/////////////////
    		//NSString *Count=[NSString stringWithFormat:@"%d",ct];*/
    		
    		text=[[UITextField alloc] initWithFrame:rect];
    		text.backgroundColor=[UIColor redColor];
    		text.textColor=[UIColor greenColor];
    		//[text setEnabled:NO];
    		
    		text.delegate=self;
    		text.text=CallValue;
    	    [self addSubview:text];
    	}
    	return self;
    }
    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    	//text.text=@"HyTech";
    	[theTextField resignFirstResponder];
    	return YES;
    }
    - (void)dealloc {
    	[super dealloc];
    }
    
    Your help would be appriciated.
    Have a great time.

    Thanks in Advance.
    Amit Kushvaha
  2. asrekik

    asrekik New Member

    Joined:
    Jan 10, 2010
    Messages:
    5
    Likes Received:
    0
    Device:
    iPhone 3G (White)
    Dear Amit
    i'd like to develop an iphone application that sends an ussd command to the gsm network in order to display the account balance for prepaid user
    to to this, i have to use the core telephony framework but i don't find any articles or samples explain this framework
  3. sumit_rose

    sumit_rose New Member

    Joined:
    Mar 3, 2010
    Messages:
    2
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Want to use coretelephony services into my application...

    Hi,

    Please help me, i want to learn from scratch how to use coretelephony api into our application.. i want to develop an application for a jailbreaked iphone in which i want to use my API to receive calls and dial calls and SMS. I dont want to use apples dial pad or sms application. if u have code please mail me @ sksingh.rose19@gmail.com

    Please help me.
    Thankx in advance.

    Please Register or Log in to view images

Share This Page