Bronze Challenge: no idea why it doesn't work


First, my code. I’ve even removed anything involving changing the screen colors, and simply trying to post a notification, but to no avail.


[code]#import <UIKit/UIKit.h>

@interface HeavyViewController : UIViewController



[code]@implementation HeavyViewController

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)x {
    return (x == UIInterfaceOrientationPortrait) || UIInterfaceOrientationIsLandscape(x);

  • (void)sensorStateChange:(NSNotification *)note {
    if ([[UIDevice currentDevice] proximityState] == YES) {
    } else {
    NSLog(@“End of sensor state change notification”);


[code]#import <UIKit/UIKit.h>

@interface RotationAppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;



[code]#import “RotationAppDelegate.h”
#import “HeavyViewController.h”

@implementation RotationAppDelegate
@synthesize window = _window;

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    // Get the device object
    UIDevice *device = [UIDevice currentDevice];

    // Tell it to start monitoring the accelerometer for orientation
    [device beginGeneratingDeviceOrientationNotifications];

    // Get the notification center for the app
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

    // Add yourself as an observer
    [nc addObserver:self

    // Now, set the device to enable proximity monitoring
    [device setProximityMonitoringEnabled:YES];
    NSLog(@“Proximity monitoring enabled? %@”, [device isProximityMonitoringEnabled] ? @“YES” : @“NO”);

    HeavyViewController *hvc = [[HeavyViewController alloc] init];
    [nc addObserver:hvc
    [[self window] setRootViewController:hvc];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;

  • (void)orientationChanged:(NSNotification *)note {
    // Log the constant that represents the current orientation
    NSLog(@“orientationChanged: %d”, [[note object] orientation]);


I’ve tried simply copy-pasting other poster’s successful solutions and running them, and it still gets nothing. Is there a chance my physical proximity sensor is broken? Or is it some really obvious thing I’m missing in the code.

Any and all help appreciated!


Just ran your code on my phone- it works fine. You’re not trying in landscape mode, are you? See

You can also test your proximity sensor by making a phone call to yourself. Placing your hand over the earpiece should dim the screen during an active call. If not, it’s broken.

Finally, this should be obvious but only iPhones have proximity sensors (not iPod Touch nor iPads). Good luck!


… that did it. Thank you so much!


“You’re not trying in landscape mode, are you?”

This was my problem. This is after the part of the chapter where you force landscape only, and I didn’t realize the sensor did not work in landscape setting. Thanks!