我正试图在我的iPhone应用程序中获取通话事件。 为此,我试图注册核心电话通知,但我收到以下错误。我正在iPhone 3GS上测试它。
Undefined symbols for architecture armv7:
"CTTelephonyCenterGetDefault()", referenced from:
-[CallEventAppDelegate application:didFinishLaunchingWithOptions:] in CallEventAppDelegate.o
ld: symbol(s) not found for architecture armv7
以下是我的示例代码: -
void (*CTTelephonyCenterAddObserver) (id,id,CFNotificationCallback,NSString*,void*,int);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// register for all Core Telephony notifications
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct, // center
NULL, // observer
telephonyEventCallback, // callback
NULL, // event name (or all)
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
return YES;
}
static void telephonyEventCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSString *notifyname = (__bridge NSString*)name;
if ([notifyname isEqualToString:@"kCTCallIdentificationChangeNotification"])
{
NSDictionary* info = (__bridge NSDictionary*)userInfo;
//CTCall* call = (CTCall*)[[[info objectForKey:@"kCTCall"] stringValue] isEqualToString:@"4"];
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");
}
}
}
提前致谢。
答案 0 :(得分:1)
您必须包含核心电话框架并将其导入 CallEventAppDelegate
#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>