WKInterfaceDevice对象提供苹果表的信息,拿到苹果表的信息去决定app 展示的内容,当app 处于工作状态,可以WKInterfaceDevice对象去触觉回溃。
一、简介
不要用WKInterfaceDevice通过初化创建子类,要通过 currentDevice类方法,得到当前设备对象。
二、属性和方法
@interface WKInterfaceDevice : NSObject
//通过此类方法得到当前的设备
+ (WKInterfaceDevice *)currentDevice;
//在设备中存储图片,类似字典形式,此方法在watch是用不了
//本来可以用来存储图片,20M。
- (BOOL)addCachedImage:(UIImage *)image name:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
//在设备中存储图片,类似字典形式,此方法在watch是用不了
- (BOOL)addCachedImageWithData:(NSData *)imageData name:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
//移除设备中存储图片,类似字典形式,此方法在watch是用不了
- (void)removeCachedImageWithName:(NSString *)name WK_AVAILABLE_IOS_ONLY(8.2);
//移除设备中所有存储的图片,此方法在watch是用不了
- (void)removeAllCachedImages WK_AVAILABLE_IOS_ONLY(8.2);
//得到内存中图片的信息,此方法在watch是用不了
@property (nonatomic, readonly, strong) NSDictionary<NSString*, NSNumber*> *cachedImages WK_AVAILABLE_IOS_ONLY(8.2); // name and size of cached images
//得到屏幕的 bounds
@property (nonatomic, readonly) CGRect screenBounds;
//当前watch 像素
@property (nonatomic, readonly) CGFloat screenScale;
//字体 得到结果 “UICTContentSizeCategoryS”
@property (nonatomic, readonly, copy) NSString *preferredContentSizeCategory;
//用户界面 布局方向
//WKInterfaceLayoutDirectionLeftToRight 右边
// WKInterfaceLayoutDirectionRightToLeft 左边
@property (nonatomic, readonly) WKInterfaceLayoutDirection layoutDirection WK_AVAILABLE_WATCHOS_ONLY(2.1);
//手表佩戴那只手上
//WKInterfaceDeviceWristLocationLeft 左边
//WKInterfaceDeviceWristLocationRight 右边
@property (nonatomic,readonly) WKInterfaceDeviceWristLocation wristLocation WK_AVAILABLE_WATCHOS_ONLY(3.0);
//crown的位置
// WKInterfaceDeviceCrownOrientationLeft 左边
//WKInterfaceDeviceCrownOrientationRight 右边
@property (nonatomic,readonly) WKInterfaceDeviceCrownOrientation crownOrientation WK_AVAILABLE_WATCHOS_ONLY(3.0);
//返回用户界面方向
+ (WKInterfaceLayoutDirection)interfaceLayoutDirectionForSemanticContentAttribute:(WKInterfaceSemanticContentAttribute)semanticContentAttribute WK_AVAILABLE_WATCHOS_ONLY(2.1);
//系统的版本 如 "2.0"
@property(nonatomic, readonly, copy) NSString *systemVersion WK_AVAILABLE_WATCHOS_IOS(2.0,9.0); // e.g. @"2.0"
//得到表名字
@property(nonatomic, readonly, copy) NSString *name WK_AVAILABLE_WATCHOS_IOS(2.0,9.0); // e.g. "My Watch"
// 机型 如"Apple Watch"
@property(nonatomic, readonly, copy) NSString *model WK_AVAILABLE_WATCHOS_IOS(2.0,9.0); // e.g. @"Apple Watch"
//本地模型信息版本 印结果 是: Apple Watch
@property(nonatomic, readonly, copy) NSString *localizedModel WK_AVAILABLE_WATCHOS_IOS(2.0,9.0); // localized version of model
//表的系统 如"watchOS"
@property(nonatomic, readonly, copy) NSString *systemName WK_AVAILABLE_WATCHOS_IOS(2.0,9.0); // e.g. @"watchOS"
#if TARGET_OS_WATCH
//api 没有提示
//WKWaterResistanceRatingIPX7
//WKWaterResistanceRatingWR50
@property (nonatomic,readonly) WKWaterResistanceRating waterResistanceRating WK_AVAILABLE_WATCHOS_ONLY(3.0);
#endif
//给用户触觉回馈
- (void)playHaptic:(WKHapticType)type WK_AVAILABLE_WATCHOS_ONLY(2.0);
@end
本人在工作中,用到WKInterfaceDevice,如下两点:
1.存储图片,addCachedImageWithData方法,现在不能用了。
2.通过systemVersion属性,得到表的版本。
over,有足的地方,望指正,感谢!!
网友评论