| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /************************************************************
- * * Hyphenate CONFIDENTIAL
- * __________________
- * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
- *
- * NOTICE: All information contained herein is, and remains
- * the property of Hyphenate Inc.
- * Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained
- * from Hyphenate Inc.
- */
- #import <UIKit/UIKit.h>
- #import "EMCDDeviceManager+ProximitySensor.h"
- @implementation EMCDDeviceManager (ProximitySensor)
- @dynamic isSupportProximitySensor;
- @dynamic isCloseToUser;
- #pragma mark - proximity sensor
- - (BOOL)isProximitySensorEnabled {
- BOOL ret = NO;
- ret = self.isSupportProximitySensor && [UIDevice currentDevice].proximityMonitoringEnabled;
-
- return ret;
- }
- - (BOOL)enableProximitySensor {
- BOOL ret = NO;
- if (_isSupportProximitySensor) {
- [[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
- ret = YES;
- }
-
- return ret;
- }
- - (BOOL)disableProximitySensor {
- BOOL ret = NO;
- if (_isSupportProximitySensor) {
- [[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
- _isCloseToUser = NO;
- ret = YES;
- }
-
- return ret;
- }
- - (void)sensorStateChanged:(NSNotification *)notification {
- BOOL ret = NO;
- if ([[UIDevice currentDevice] proximityState] == YES) {
- ret = YES;
- }
- _isCloseToUser = ret;
- if([self.delegate respondsToSelector:@selector(proximitySensorChanged:)]){
- [self.delegate proximitySensorChanged:_isCloseToUser];
- }
- }
- #pragma mark - getter
- - (BOOL)isCloseToUser {
- return _isCloseToUser;
- }
- - (BOOL)isSupportProximitySensor {
- return _isSupportProximitySensor;
- }
- @end
|