distance sensor , implemented in the form of registered notifications
#import "ViewController.h"
@interface viewcontroller ()
@end
@implementation Viewcontroller
-(void) viewdidload {
[Super viewdidload];
//1. Open distance sensor
[uidevice currentdevice]. proximitymonitoringenabled=YES;
//2 Registration notification for monitoring
[[nsnotificationcenter defaultcenter]addobserver:self selector:@ Selector(proximitymonitoring) name:uideviceproximitystatedidchangenotification Object:nil];
}
-(void) proximitymonitoring
{
BOOL state=[uidevice currentdevice]. Proximitystate;
if (state) {
NSLog(@ " near ");
}
Else
{
NSLog(@ " far ");
}
}
-(void) Motionbegan: (uieventsubtype) motion withevent: (uievent *) event
{
NSLog(@ " mobile phone comes with , shake phone trigger event ");
}
-(void) motionended: (uieventsubtype) motion withevent: (uievent *) event
{
NSLog(@ " Shake end ");
}
-(void) motioncancelled: (uieventsubtype) motion withevent: (uievent *) Event
{
NSLog(@ " shake is terminated to trigger event ( incoming call )");
}
-(void) Dealloc
{
[[nsnotificationcenter defaultcenter]removeobserver:self];
}
@end
iOS distance sensor and shake shake