I am trying to change the screen shot that is automatically captured by iOS when the app enters the background.
However I am not entirely sure exactly when this screenshot is taken.
For example:
If you pull down the notification bar while in the app the following method is called:
- (void) applicationWillResignActive:(UIApplication *) application {
}
Also if you double tap the home button while in the app the same method is called. In addition if an alert view is show 'applicationWillResignActive' is called.
But in both of these cases
- (void) applicationDidEnterBackground:(UIApplication *) application {
}
is not called.
So my question is, is there a screenshot captured after the call to applicationWillResignActive even if the application does not enter the background? Or does iOS only capture a screenshot after applicationDidEnterBackground?
Look at official doc - "Preventing Sensitive Information From Appearing In The Task Switcher".
It says applicationDidEnterBackground: should be used for the said purpose.
you can look over here, in summary, change the view before return from applicationDidEnterBackground:
Yes.
- (void) applicationWillResignActive:(UIApplication *) application {
}
is called when you pull down the notification bar or even when you double click the home button. You have to do something here to prevent your sensitive information to be captured by the OS. One workaround might be:
Set a blurry screen overlay before the app goes in the background
Once the app becomes active remove this overlay
Something like this:
-(void)applicationWillResignActive:(UIApplication *)application
{
imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
[imageView setImage:[UIImage imageNamed:#"blurryImage.png"]];
[self.window addSubview:imageView];
}
And then remove this overlay before the application enters foreground:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(imageView != nil) {
[imageView removeFromSuperview];
imageView = nil;
}
}
is called when you pull down the notification bar or even when you double click the home button. You have to do something here to prevent your sensitive information to be captured by the OS. One workaround might be:
Set a blurry screen overlay before the app goes in the background
Once the app becomes active remove this overlay
Related
This question already has answers here:
Prevent iOS from taking screen capture of app before going into background
(10 answers)
Closed 3 years ago.
I am new to IOS development
I want to remove my application from recent apps which is developed in Objective C.
I tried UIApplicationExitsOnSuspend in
info.plist
, but no luck still application is showing in info.plist.
Can anyone help me on this.
Thanks in Advance !!!
You could use concept of the cover window.
When app will resign active state you show your cover, and system will take snapshot of that cover instead of last visible UIViewController.
When app will become active you hide and deallocate your cover window.
Here is example
#import "AppDelegate.h"
#interface AppDelegate ()
#property (nonatomic) UIWindow *coverWindow;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
self.coverWindow = UIWindow.new;
self.coverWindow.rootViewController = UIViewController.new;
[self.coverWindow makeKeyAndVisible];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self.coverWindow removeFromSuperview];
self.coverWindow = nil;
}
#end
UIApplicationExitsOnSuspend is deprecated. You shouldn't use it any more. There has been reports of apple rejecting apps with that key. As per apple:
Deprecated
The system now automatically suspends apps leaving the foreground when
they don’t require background execution. For more information, see
About the Background Execution Sequence.
So for now, you are stuck with letting apple handle the background state of apps. Forcefully trying to exit the app by any manner would lead to a rejection from App Store.
UPDATE
I just noticed your comment saying what you actually want. To prevent the Background Snapshot, you can add a custom view to the window. This is similar to the answer posted by Mark Agranal below, but the thing is you don't need to add a new Window or new ViewController. You can simply add a custom view to the window and remove the view when the app reenters active state. In your AppDelegate:
// The view to use as a mask
#property (nonatomic, weak) UIView* coverView;
// Add the view to window
-(void)applicationWillResignActive:(UIApplication *)application
{
coverView = [[UIView alloc]initWithFrame:[self.window frame]];
[self.window addSubview:coverView];
}
// Remove the view to window
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(coverView != nil) {
[coverView removeFromSuperview];
coverView = nil;
}
}
Note that you can add any view to the window using the above method. The system will take screenshot of the added view and hence the sensitive user data will be protected.
I use this code in AppDelegate:
- (BOOL)accessibilityPerformMagicTap {
NSLog(#"Appdelegate = %s",__func__);
return YES;
}
When I click the home button and two-fingered double tap while using VoiceOver activates, this method is not invoked. What is the reason for this? How can I use this method with my music app?
You cannot. The method is called on the focused accessibility element while the app is foregrounded.
My case is the following: I have a Cordova application that has to run on iOS. I have to prevent sensitive information from being shown in the app switcher when the app is being in background.
Apple provides this solution for native applications which doesn't seem to solve my problem, because it doesn't manipulate the web view in any way.
I wonder if I can natively place some static image covering the webview. As I understand the system takes a screenshot of the view right after the applicationDidEnterBackground: method is invoked.
This way the system will take a screenshot of the image I put on top instead of the actual content of the webview.
I'm not an experienced iOS developer and I will appreciate any suggestion.
Thanks.
It turned out apple's solution could fix the problem with a small edit from me.
Instead of implementing
- (void)applicationDidEnterBackground:(UIApplication *)application
I implemented
-(void)applicationWillResignActive:(UIApplication *)application
Then no matter if you hit the home button once or twice, it will cover the viewcontroller with the blank one just created.
-(void)applicationWillResignActive:(UIApplication *)application {
UIViewController *blankViewController = [UIViewController new];
//this is how to attach image
UIImage *splashImage = [UIImage imageNamed:#"some image"];
blankViewController.view.backgroundColor = [UIColor colorWithPatternImage: splashImage];
// set some transition style
blankViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self.window.rootViewController presentViewController:blankViewController animated:YES completion:NULL];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}
This question already has answers here:
Controlling the screenshot in the iOS 7 multitasking switcher
(8 answers)
Closed 9 years ago.
I have an application that contains some sensitive information, I don't want others to snapshot the screen before app enter background, so I want to present a pattern lock viewController on the screen after user press home button. I tried this code
- (void)applicationWillResignActive:(UIApplication *)application
{
PatternLockViewController *pvc = [[SMICConfig sharedSMICConfig] patternLockVC];
if (!(pvc.isViewLoaded && pvc.view.window) && [SMICConfig sharedSMICConfig].isCookie) {
[self.window.rootViewController presentViewController:pvc animated:NO completion:nil];
}
}
But the PatternLockViewController only present after the app enter foreground. So, when the app stay in background, you can double-click home button to peek some information.
Tecent qq's pattern lock is very well. I just want to implement this effect.
Can any one help me? Thanks
You can tell iOS7 to avoid using the recent snapshot image during the next launch cycle by calling ignoreSnapshotOnNextApplicationLaunch Apple's documentation
The following is how I implemented for my App. Hope it helps.
- (void)applicationWillResignActive:(UIApplication *)application {
[application ignoreSnapshotOnNextApplicationLaunch];
self.imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
[self.imageView setImage:[UIImage imageNamed:#"Default-568h"]];
[self.window addSubview: self.imageView];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (self.imageView != nil) {
[self.imageView removeFromSuperview];
self.imageView = nil;
}
}
I need to display a popup or something like a splash screen every time I start my app. The content of this popup must be taken from an external web source (something like jpg, png or pdf).
The purpose of this popup is to warn users about news and special offers. The popup should disappear after a certain time (or at the pressure of a button).
From what I read on other threads, the UIPopoverController feature seems be helpful for what I need (as I read in this class reference), but I'm afraid that the main function of this popup is presenting a choice in result of the pressure of a button.
Why can you not simply add a webview to the screen when the app opens?
Like:
in appDelegate:
UIWebview *popover;
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
popover = [[UIWebView alloc] initWithFrame:win.bounds];
... load content ...
[win addSubview:popover];
[self performSelector:#selector(dismissPopover) withObject:nil afterDelay:3];
}
-(void)dismissPopover
{
[popover removeFromSuperview];
}