2014-01-21 16 views
1

在我的应用程序中,我试图在用户收到一些电话时上传一些数据。那么,是否有可能通过GSM数据网络上传数据,无论是打电话还是打电话?谢谢。通过移动网络上传数据 - 目标C

+1

您是否试图记录呼叫并将数据发送给您?根据我的信息,如果您有3G或更高版本的互联网,我们可以使用互联网 –

回答

2

您可以使用Core Telephony framework中的CTCallCenter类来注册事件处理程序,以便在通话开始或结束时通知您的应用程序,并且您可以在其中执行任何操作。

的CTCall提供了以下callState财产

CTCallStateDialing

CTCallStateIncoming

CTCallStateConnected

CTCallStateDisconnected

希望它可以帮助你解决你的问题。

0

首先,您需要在您的项目中添加CoreTelephony框架。

请尝试下面的代码。它会让你清楚地理解流程。

#import <CoreTelephony/CTCall.h> 
#import <CoreTelephony/CTCallCenter.h> 

static CTCallCenter *callCenter; 

@implementation AppDelegate 

- (void)dealloc 
{ 
    [_window release]; 
    [_viewController release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 



    if([[UIDevice currentDevice].systemVersion floatValue] >= 4.0) 
    { 
     callCenter = [[CTCallCenter alloc] init]; 
     callCenter.callEventHandler=^(CTCall* call) 
     { 
      NSLog(@":: Call id:%@",call.callID); 
      if (call.callState==CTCallStateDialing) 
      { 
       NSLog(@":: Call state:dialing"); 

      } 
      if (call.callState==CTCallStateIncoming) 
      { 
       NSLog(@":: Call state:incoming"); 
      } 
      if (call.callState==CTCallStateConnected) 
      { 
       NSLog(@":: Call state:Connected");     
      } 
      if (call.callState==CTCallStateDisconnected) 
      { 
       NSLog(@":: Call state:Disconnected"); 
      } 
     }; 
    } 


    return YES; 
}