How hide or close my app when i reveive a call? - ios

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.

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.

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'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];
}

Related

Detect AirPlay Mirroring in iOS application

I have an iOS app built in XCode with Objective C mainly for iPads.
Basically I want to detect inside my application of AirPlay Mirroring is active, so mainly if the device is mirroring to another screen.
I searched all around stackoverflow but I couldn't find what I needed for this.
Some answers said that I have to use UIScreenDidConnectNotification for this.
The thing is that I have to call a function if the mirroring is active or when mirroring is activated, also when mirroring is stopped. So I think I need a listener for the mirroring changes.
Can you please help me?
I am relatively new to iOS development so please don't get upset if I may not know all things.:)
Some answers I've found :
https://stackoverflow.com/a/30319663/2866662
https://stackoverflow.com/a/22321926/2866662
https://stackoverflow.com/a/9027616/2866662
https://stackoverflow.com/a/10576262/2866662
Thanks!
Here's how you can call any function by subscribing to the notification, you can do it in viewDidLoad or where you find necessary:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receiveAirPlayNotification:)
name: UIScreenDidConnectNotification
object:nil];
And to receive it:
- (void) receiveAirPlayNotification:(NSNotification *) notification
{
//Do whatever you want here, or call another function
NSLog(#"Received Notification - %#", notification);
[self doMyThing];
}

Is it possible that NSNotificationCenter doesn't work on certain devices?

Am using NSNotificationCenter in my iPhone App to post a notification
// I add an observer in didFinishLanchingWithOptions() in the AppDelegate
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(getData:) name:kNotif_GetData object:nil];
....
....
// then in another method, I post the notification
[[NSNotificationCenter defaultCenter] postNotificationName:kNotif_GetData object:nil];
....
One user says that this functionality (which is executed by getData()) is not working. so that might mean that the notification hasn't gotten fired. Any idea why this might happen? When I test it with different devices, it works perfect. The user uses iPhone5 and iOS7. Is there any more setting or any explicit user setting which is needed or which could turn this on/off?
No, notification centre is reliable.
"Not working" is not enough information to diagnose the problem. Get more information from the user or add more logging so that you know what is actually going on.

Keep ios keyboard open

I have a ios app that launch a UIWebView and you can interact with this web (the app is like a container). In the interaction with the web you need the keyboard a lot. So, I want (if it's possible) to keep the keyboard always open.
I've found some solutions, but none of them work for me.
I've tried with:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
and I able to detect when the keyboard are going to hide, but I don't know what I can do in keyboardDidHide method to avoid the keyboard to be closed.
I've tried also with:
webView.keyboardDisplayRequiresUserAction
But nothing happens.
Do you know how I can do this?
Thanks!
You can try playing with UIViewController's disablesAutomaticKeyboardDismissal property. Try overriding this property and returning NO.

Application does not run in background simply does not work

I have read over many stack overflow questions where people ask to terminate their app oppose to let it run in the background.
The main answer I found was to set the application does not run in background BOOL to YES in my info.plist
I have done this and cleaned my project but still my application runs in the background when the user presses the home button. This solution simply does not work.
What can I do to make my application quit when a user presses the home button.
My app is currently running on iOS 6.
Any help is appreciated :)
This answer is for your first comment, not the original question. Have your iPod view controller register for the UIApplicationDidEnterBackgroundNotification notification. The implementation should stop the music. This is a much better user experience than choosing to have your app terminate on suspend.
// Put this in a good place like viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil];
// Handle the notification
- (void)backgrounding {
// app is leaving the foreground, stop the music
}
// In your dealloc method add:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];

Is it possible to detect if a user takes a screenshot in iOS? [duplicate]

Is there a notification or other mechanism of being informed that the user is taking a screenshot with the home/power buttons?
I've seen threads about wanting to disable the taking of screenshots, but that's not what I'm looking to do.
I have a photographer client who's concerned that his works will be copied by means of users taking screenshots and I thought that if there was an opportunity to put a watermark across the image before the screenshot was taken, that would allay his fears.
The PictureWasTakenNotification Darwin notification will be sent when the user takes a screenshot. However, this is sent after the screenshot is taken.
(No notifications will be sent before the screenshot was taken.)
Here's a way which might work, although it will totally go against user interface guidelines I'm sure. If you force the user to have their finger on the screen for the image to show then I don't think they can create screenshots. Because as soon as you press the home+lock keys to actually take the screenshot, the screen seems to behave as if there are no fingers touching it. Try taking a screenshot while moving between home screens to see what I mean.
Not a perfect solution by any means but you may be able to work it into your app design if you're really clever without it detracting too much from the user experience (a tough challenge though!). Nevertheless, I believe this may allow you to display artwork/photos without allowing users to take screenshots.
Since iOS 7 the UIApplicationUserDidTakeScreenshotNotification exists. So doing something like this should detect the screenshots:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(userDidTakeScreenshot) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}
- (void)userDidTakeScreenshot {
// Screenshot taken, act accordingly.
}
Finally, don't forget to remove the observer:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}
What's really needed is a notification that is sent before the actual screen capture happens. A delegate method or some other means of giving the app a screenshotting-in-flight opportunity to redraw your content before the grab happens.
And there isn't one.

Resources