Bronze challenge


I have done this challenge but, as I don’t have developer account, I can’t test the app in my iphone, so I would like to compare the solution with yours.

In RotationAppDelegate.m, didFinishLaunchingWithOptions :

[device setProximityMonitoringEnabled:YES];

[nc addObserver:self selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:device];

- (void)proximityChanged:(NSNotification *)note
    NSLog(@"proximity changed: %@", [note object]);
    [[hvc view] setBackgroundColor:[UIColor darkGrayColor]];

And I declared the HeavyViewController in the delegate.h, so I could use it in the didFinishLaunchingWithOptions method and proximityChanged selector.


@jjalcazar Since we are changing the background of HeavyViewController’s view, change the addObserver: of the proximity change notification to be hvc rather than self:


[nc addObserver:hvc selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:device];

Also, your proximityChanged: method should be generating an error like: "Use of undeclared identifier ‘hvc’. In this case, hvc is a local variable storing a pointer from a method outside the scope of proximityChanged:. Move your proximityChanged: method into the HeavyViewController.m file and change the code to [self view] instead of [hvc view]:


- (void)proximityChanged:(NSNotification *)note { NSLog(@"proximityChanged: %d", [[note object] proximityState]); [[self view] setBackgroundColor:[UIColor darkGrayColor]]; }


this is my solution

RotationAppDelegate.m didFinishLaunchingWithOptions

[nc addObserver:self 

-(void)sensorStateChanged:(NSNotification *)note{
    self.window.rootViewController.view.backgroundColor = [UIColor grayColor];