私はあなたのコードをテストしませんでしたが、あなたの問題は、コアテレフォニー通知センターを使用してそのイベントに登録する必要があることだと思います(コメントのコードにあったものではありません)。このようなもの:
// register for all Core Telephony notifications
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(ct, // center
NULL, // observer
telephonyEventCallback, // callback
NULL, // event name (or all)
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
コールバック関数は
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");
}
}
}
私はここでこの同様の質問で別のテクニックを提供します。UIApplication
また、バックグラウンドに置かれた通知を受け取らないことについてのその質問の私のコメントに注意してください。
更新:kCTCallStatus
iOS6での代わりに使用することについての以下のcud_programmerのコメントを参照してくださいkCTCall
。