iphone: how to detect last caller number programmatically?

后端 未结 4 1742
攒了一身酷
攒了一身酷 2021-01-14 21:10

Is there any way to detect last caller number & call duration on iPhone, I am able to get all notification (Core Telephony) but don\'t know how to get caller number.

4条回答
  •  借酒劲吻你
    2021-01-14 21:50

    You can use this

    if ([name isEqualToString:@"kCTCallIdentificationChangeNotification"])
        {
            // CTCallCenter *center = [[CTCallCenter alloc] init];
            // center.callEventHandler = ^(CTCall *call) {
            // NSLog(@”call:%@”, [call description]);
            // };
    
            //NSDictionary *info = (NSDictionary *)userInfo;
            CTCall *call = (CTCall *)[info objectForKey:@"kCTCall"];
            NSString *caller = CTCallCopyAddress(NULL, call);
            NSLog(@"caller:%@",caller);
            //CTCallDisconnect(call);
            /* or one of the following functions: CTCallAnswer
             CTCallAnswerEndingActive
             CTCallAnswerEndingAllOthers
             CTCallAnswerEndingHeld
             */
    
            //if ([caller isEqualToString:@"+1555665753"])
            if ([caller isEqualToString:@"+918740061911"])
            {
                NSLog(@"disconnecting call");
                //disconnect this call
                CTCallDisconnect(call);
    
            }
    
        }
    

提交回复
热议问题