Skip to content

Instantly share code, notes, and snippets.

@appsandwich
Created July 16, 2013 10:50
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save appsandwich/6007702 to your computer and use it in GitHub Desktop.
Save appsandwich/6007702 to your computer and use it in GitHub Desktop.
iOS - Simulate on-device memory warnings using volume button press
#if DEBUG
#import <MediaPlayer/MediaPlayer.h>
#endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if DEBUG
// Debug code that lets us simulate memory warnings by pressing the device's volume buttons.
// Don't ever ship this code, as it will be rejected by Apple.
MPVolumeView *volume = [[MPVolumeView alloc] initWithFrame:CGRectZero];
[self.window addSubview:volume];
// Register to receive the button-press notifications
__block id volumeObserver;
volumeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"Manually simulating a memory warning.");
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
}];
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment