< UIKit >

UIDevice.h

2019-06-20  本文已影响0人  zhYx_

#if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UIDevice.h>)
//
//  UIDevice.h
//  UIKit
//
//  Copyright (c) 2007-2018 Apple Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKitDefines.h>
NS_ASSUME_NONNULL_BEGIN





/* 设备方向 <枚举> */
typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
    UIDeviceOrientationUnknown,             /// 未知
    UIDeviceOrientationPortrait,            /// 垂直(home键在下)
    UIDeviceOrientationPortraitUpsideDown,  /// 反向垂直(home键在上)
    UIDeviceOrientationLandscapeLeft,       /// 左旋转(home键在右)
    UIDeviceOrientationLandscapeRight,      /// 右旋转(home键在左)
    UIDeviceOrientationFaceUp,              /// 向上(正面朝上)
    UIDeviceOrientationFaceDown,            /// 向下(正面朝下)
} __TVOS_PROHIBITED;

/* 电池状态 <枚举> */
typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {
    UIDeviceBatteryStateUnknown,    /// 未知
    UIDeviceBatteryStateUnplugged,  /// 未插电
    UIDeviceBatteryStateCharging,   /// 充电(未到100%)
    UIDeviceBatteryStateFull,       /// 充电(已经100%)
} __TVOS_PROHIBITED;

/* UI风格 <枚举> */
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
    UIUserInterfaceIdiomUnspecified = -1,                   /// 未知
    UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2),   /// iPhone和iPod touch风格
    UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2),     /// iPad风格
    UIUserInterfaceIdiomTV NS_ENUM_AVAILABLE_IOS(9_0),      /// Apple TV风格
    UIUserInterfaceIdiomCarPlay NS_ENUM_AVAILABLE_IOS(9_0), /// CarPlay风格
};



// 设备是否处于纵向方向
static inline BOOL UIDeviceOrientationIsPortrait(UIDeviceOrientation orientation)  __TVOS_PROHIBITED {
    return ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown);
}
// 设备是否处于横向方向
static inline BOOL UIDeviceOrientationIsLandscape(UIDeviceOrientation orientation)  __TVOS_PROHIBITED {
    return ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight);
}
// 指示指定的方向是面朝上还是面朝下
static inline __attribute__((always_inline)) BOOL UIDeviceOrientationIsFlat(UIDeviceOrientation orientation)  __TVOS_PROHIBITED {
    return ((orientation) == UIDeviceOrientationFaceUp || (orientation) == UIDeviceOrientationFaceDown);
}
// 指示指定的方向是纵向还是横向方向
static inline __attribute__((always_inline)) BOOL UIDeviceOrientationIsValidInterfaceOrientation(UIDeviceOrientation orientation)  __TVOS_PROHIBITED {
    return ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown || (orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight);
}





#pragma mark - 设备 Class
#pragma mark -
/*
 - 单例
 */
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIDevice : NSObject

// 获取 设备类
#if UIKIT_DEFINE_AS_PROPERTIES
@property(class, nonatomic, readonly) UIDevice *currentDevice;
#else
+ (UIDevice *)currentDevice;
#endif

/// 获取 设备名(用户自定义的设备名称)
@property(nonatomic,readonly,strong) NSString *name;
/// 获取 型号(如:iPhone/iPad)
@property(nonatomic,readonly,strong) NSString *model;
/// 获取 本地型号(如:iPhone/iPad)
@property(nonatomic,readonly,strong) NSString *localizedModel;
/// 获取 系统名称(如:iOS/tvOS)
@property(nonatomic,readonly,strong) NSString *systemName;
/// 获取 系统版本(如:12.0)
@property(nonatomic,readonly,strong) NSString *systemVersion;
/// 获取 设备方向(除非正在生成设备方向通知,否则返回UIDeviceOrientationUnknown)
@property(nonatomic,readonly) UIDeviceOrientation orientation __TVOS_PROHIBITED;
/// 获取 UUID(供应商ID;运行在同一设备,同一供应商的所有App,UUID都相同;同一设备,不同供应商的App,UUID不相同;不同设备的App,无论供应商是否相同,UUID都不同;如果设备删除某个供应商的所有App,再重新安装,UUID会改变;)
@property(nullable, nonatomic,readonly,strong) NSUUID *identifierForVendor NS_AVAILABLE_IOS(6_0);
/// 是否生成设备方向通知
@property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications __TVOS_PROHIBITED;

// 开始生成设备方向通知(嵌套)
- (void)beginGeneratingDeviceOrientationNotifications __TVOS_PROHIBITED;
// 结束生成设备方向通知
- (void)endGeneratingDeviceOrientationNotifications __TVOS_PROHIBITED;

/// 是否启动电池监控(默认:NO)
@property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
/// 获取 电池状态(没有监控电池时返回UIDeviceBatteryStateUnknown)
@property(nonatomic,readonly) UIDeviceBatteryState batteryState NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
/// 获取 电池电量(返回[0,1.0];电池状态为UIDeviceBatteryStateUnknown时返回-1.0;)
@property(nonatomic,readonly) float batteryLevel NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
/// 是否启动接近监控(如接电话时脸靠近屏幕;默认:NO;)
@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled NS_AVAILABLE_IOS(3_0);
/// 是否有接近感应器(如果设备不支持接近感应,则返回NO)
@property(nonatomic,readonly)                            BOOL proximityState NS_AVAILABLE_IOS(3_0);
/// 是否支持多任务
@property(nonatomic,readonly,getter=isMultitaskingSupported) BOOL multitaskingSupported NS_AVAILABLE_IOS(4_0);
/// 获取 UI风格(用户界面模式)
@property(nonatomic,readonly) UIUserInterfaceIdiom userInterfaceIdiom NS_AVAILABLE_IOS(3_2);

// 播放一个输入的声音(当屏幕上启用了键盘且用户已经开始点击时,才会执行此方法)
- (void)playInputClick NS_AVAILABLE_IOS(4_2);

@end





///!!!: 键盘的音频反馈 <协议>
@protocol UIInputViewAudioFeedback <NSObject>

@optional
/// 自定义的视图是否播放输入声音
@property (nonatomic, readonly) BOOL enableInputClicksWhenVisible;

@end





/* UI风格函数(适用于iOS3.2之前的系统;iOS3.2之后的系统可以用userInterfaceIdiom属性) */
static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() {
    return ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ?
            [[UIDevice currentDevice] userInterfaceIdiom] :
            UIUserInterfaceIdiomPhone);
}



/// 屏幕方向变化通知
UIKIT_EXTERN NSNotificationName const UIDeviceOrientationDidChangeNotification __TVOS_PROHIBITED;
/// 电池状态变化通知
UIKIT_EXTERN NSNotificationName const UIDeviceBatteryStateDidChangeNotification   NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
/// 电池电量变化通知
UIKIT_EXTERN NSNotificationName const UIDeviceBatteryLevelDidChangeNotification   NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
/// 接近传感器状态变化通知(如设备贴近了使用者的脸部)
UIKIT_EXTERN NSNotificationName const UIDeviceProximityStateDidChangeNotification NS_AVAILABLE_IOS(3_0);






NS_ASSUME_NONNULL_END

#else
#import <UIKitCore/UIDevice.h>
#endif

上一篇下一篇

猜你喜欢

热点阅读