Created
July 16, 2013 10:50
-
-
Save appsandwich/6007702 to your computer and use it in GitHub Desktop.
iOS - Simulate on-device memory warnings using volume button press
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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