实用知识:距离传感器方法使用

来源:互联网 发布:网络平台代理 编辑:程序博客网 时间:2024/05/20 04:08
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (IBAction)btnAction:(id)sender{    // 在UIDevice类中, proximity    BOOL youmeiyoudakai = [[UIDevice currentDevice] proximityState];    // 如果不支持距离传感器, 则永远返回NO    if (youmeiyoudakai == NO) {        NSLog(@"设备不支持距离传感器 \\ 没有打开距离传感器");        return;    }    BOOL enable = [[UIDevice currentDevice] isProximityMonitoringEnabled];    if (enable) {        NSLog(@"关闭距离传感器");        [[UIDevice currentDevice] setProximityMonitoringEnabled:NO];    } else {        NSLog(@"打开距离传感器");        [[UIDevice currentDevice] setProximityMonitoringEnabled:YES];    }}@end
0 0
原创粉丝点击