How can I find out whether the user pressed the Call or the Cancel button when making a call from my app?

前端 未结 6 392
梦谈多话
梦谈多话 2020-12-05 20:48

I need to return to my app after making a call from my app, so I use this code:

NSURL *url = [NSURL URLWithString:@\"telprompt://123-4567-890\"]; 
[[UIApplic         


        
6条回答
  •  攒了一身酷
    2020-12-05 21:26

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

    The above code by @J Saprio works absolutely fine. Before it suspends the Application NSNotificationCenter call UIApplicationSuspendedNotification. Once you click the "call" it will execute the (suspended:) method. Here the catch is, every time you call NSNotificationCenter method it will give a call to (suspended:) with the increment of one. Solution is to remove the observer for NSNotificationCenter. Following is the snippet for it. It will help you to execute the following method only once.

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

提交回复
热议问题