0

I have a little bug. I'm developing an iOS App. If i receive a call, my app stays open and the screen for my entering call appears on my app. I would like to close my app if i have a call. How can i fix that?

Thanks,

J.

Malicia
  • 154
  • 1
  • 14
  • How do you mean your app stays open? As in the foreground? This should not be possible with the official SDK – rckoenes Jul 11 '14 at 14:49
  • See the answer here: http://stackoverflow.com/questions/13989030/is-there-any-way-to-programatically-send-my-iphone-app-to-the-background – klcjr89 Jul 11 '14 at 14:50

3 Answers3

0

The green, in-call status bar is not a bug but a feature. You don't need to close the app when the call comes.

Instead, make sure your views are resized properly when the in-call status bar appears.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
0

As Per Apple Human Interface guidelines

Never quit an iOS app programmatically because people tend to interpret this as a crash.
However, if external circumstances prevent your app from functioning as intended, you need
to tell your users about the situation and explain what they can do about it. Depending on
how severe the app malfunction is, you have two choices.

Display an attractive screen that describes the problem and suggests a correction. A 
screen provides feedback that reassures users that there’s nothing wrong with your app. It
puts users in control, letting them decide whether they want to take corrective action and
continue using your app or press the Home button and open a different app

If only some of your app's features are unavailable, display either a screen or an alert
when people use the feature. Display the alert only when people try to access the feature
that isn’t functioning. `

But again you handle your app accordingly when call comes by using the following notification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incomingCall:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
Srinivasan N
  • 611
  • 9
  • 20
0

Srinivasan N's answer has the incorrect observer, you'll want to add this observer which will account for all scenarios: phone calls, Personal Hotspot, GPS/navigation, etc.

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(adjustViews:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}

- (void)adjustViews:(NSNotification *)notification
{
    NSValue *rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
    CGRect newFrame;
    [rectValue getValue:&newFrame];
    NSLog(@"Changed frame to: Width: %f, Height: %f", newFrame.size.width, newFrame.size.height);

    // Adjust your views here
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
klcjr89
  • 5,862
  • 10
  • 58
  • 91