如何通过我的应用程序拨打电话时,用户是否按下了“呼叫”或“取消”按钮?

时间:2012-12-06 12:09:19

标签: iphone objective-c nsurl uiapplication

我需要从我的应用程序拨打电话后返回我的应用程序,所以我使用此代码:

NSURL *url = [NSURL URLWithString:@"telprompt://123-4567-890"]; 
[[UIApplication  sharedApplication] openURL:url]; 

当用户按下按钮执行此代码时,会显示一个警告,其中包含2个按钮,“呼叫”和“取消”。

如何确定用户是否按下了“呼叫”按钮?

6 个答案:

答案 0 :(得分:8)

这并不完美,但你可以确定"呼叫"被迫而不是"取消"通过收听UIApplicationSuspendedNotification(你有必要添加一些逻辑来忽略这个事件,当有人按下“家”键或接受来电时......可能是通过添加/删除观察者围绕呈现电话号码的逻辑:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(suspended:) name:@"UIApplicationSuspendedNotification" object:nil];

-(void)suspended:(NSNotification *) notification
{
    NSLog(@"Suspended");
}

答案 1 :(得分:6)

这是 Swift 4.2 iOS 10 + 解决方案,已通过iOS 12进行了测试,可检测到“取消”和“呼叫”按钮。

别忘了导入CallKit并使您的班级符合char = [] with open('keratin.txt') as f: for line in f: line = line.strip() for ch in line: char.append(ch) print(char) len(char) f1 = open('keratin.txt','r') f2 = open('keratin.txt','a+') lob = input('Enter length of box =') iob = input('Enter the increment of the box =') i=0 lob = 5000 iob = 1000 nob = 1 #no. of boxes for i in range (0,len(char)-lob): b = i while( b < lob + i and b < len(char)): nC = 0 nG = 0 if char[b] == 'C': nC = nC + 1 elif char[b] == 'G': nG = nG + 1 b = b + 1 print(nC) print(nG) i = i + iob nob = nob + 1

CXCallObserverDelegate

答案 2 :(得分:3)

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(suspended:) name:@"UIApplicationSuspendedNotification" object:nil];

@J Saprio的上述代码完全没问题。暂停应用程序NSNotification中心之前调用“UIApplicationSuspendedNotification”一旦单击“调用”,它将执行“(暂停:)”方法。这是捕获,每次调用NSNotification中心方法时,它将以1的增量调用(suspended :)。解决方案是删除[NSNotification center]的观察者。 FOllowing是它的片段。它将帮助您只执行一次以下方法。

-(void)suspended:(NSNotification *) notification
{
    NSLog(@"Suspended");
 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIApplicationSuspendedNotification" object:nil];

}

答案 3 :(得分:2)

根据 iOS条款,这是不可能的。完成通话时无法重定向到应用程序。

在Jailbroken Phones中,只有这样才有可能。

答案 4 :(得分:1)

当应用程序执行上面的代码时,它将退出当前的应用程序&amp;导航到iPhone的应用程序。因此,应用程序无法识别天气用户是否已按下通话或取消。希望,它会对您有所帮助。

答案 5 :(得分:0)

试试这个,我按照以下方式处理这个问题:

in - (void)viewDidLoad:

NSNotificationCenter * center =[NSNotificationCenter defaultCenter];

[center addObserverForName:UIApplicationDidBecomeActiveNotification
                    object:nil
                     queue:[NSOperationQueue mainQueue]
                usingBlock:^(NSNotification *note)
 {
     // use instance flag to know
     if (self.isBeginCallPhone)
     {
         //do some thing
         self.isBeginCallPhone = NO;
     }
 }];

不要忘记:

- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];

}

相关问题