Search code examples
iphoneiosproximitysensor

how to create Proximity Sensor observer?


i want to create and observer that checks for a change in proximity sensor. i am using this code.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChanged:) name:@"UIDeviceProximityStateDidChangeNotification" object:device];

but it give an error of "Use of undeclared identifier 'device'"

please help.


Solution

  • [[NSNotificationCenter defaultCenter] addObserver:self
                                                     selector:@selector(proximityChanged:)
                                                         name:@"UIDeviceProximityStateDidChangeNotification"
                                                       object:nil];
    

    Do like this way you set nil to objcet.