File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99#import < Foundation/Foundation.h>
1010
11+ typedef NS_OPTIONS (NSInteger , ALTDeviceType)
12+ {
13+ ALTDeviceTypeiPhone NS_SWIFT_NAME (iphone) = 1 << 1 ,
14+ ALTDeviceTypeiPad NS_SWIFT_NAME (ipad) = 1 << 2 ,
15+ ALTDeviceTypeAppleTV NS_SWIFT_NAME (appletv) = 1 << 3 ,
16+
17+ ALTDeviceTypeNone = 0 ,
18+ ALTDeviceTypeAll = (ALTDeviceTypeiPhone | ALTDeviceTypeiPad | ALTDeviceTypeAppleTV),
19+ };
20+
1121NS_ASSUME_NONNULL_BEGIN
1222
1323@interface ALTDevice : NSObject <NSCopying >
1424
1525@property (nonatomic , copy ) NSString *name;
1626@property (nonatomic , copy ) NSString *identifier;
27+ @property (nonatomic ) ALTDeviceType type;
1728
1829- (instancetype )init NS_UNAVAILABLE;
19- - (instancetype )initWithName : (NSString *)name identifier : (NSString *)identifier NS_DESIGNATED_INITIALIZER;
30+ - (instancetype )initWithName : (NSString *)name identifier : (NSString *)identifier type : (ALTDeviceType) type NS_DESIGNATED_INITIALIZER;
2031
2132@end
2233
Original file line number Diff line number Diff line change 1010
1111@implementation ALTDevice
1212
13- - (instancetype )initWithName : (NSString *)name identifier : (NSString *)identifier
13+ - (instancetype )initWithName : (NSString *)name identifier : (NSString *)identifier type : (ALTDeviceType) type
1414{
1515 self = [super init ];
1616 if (self)
1717 {
1818 _name = [name copy ];
1919 _identifier = [identifier copy ];
20+ _type = type;
2021 }
2122
2223 return self;
@@ -32,7 +33,23 @@ - (nullable instancetype)initWithResponseDictionary:(NSDictionary *)responseDict
3233 return nil ;
3334 }
3435
35- self = [self initWithName: name identifier: identifier];
36+ ALTDeviceType deviceType = ALTDeviceTypeNone;
37+
38+ NSString *deviceClass = responseDictionary[@" deviceClass" ] ?: @" iphone" ;
39+ if ([deviceClass isEqualToString: @" iphone" ])
40+ {
41+ deviceType = ALTDeviceTypeiPhone;
42+ }
43+ else if ([deviceClass isEqualToString: @" ipad" ])
44+ {
45+ deviceType = ALTDeviceTypeiPad;
46+ }
47+ else if ([deviceClass isEqualToString: @" tvOS" ])
48+ {
49+ deviceType = ALTDeviceTypeAppleTV;
50+ }
51+
52+ self = [self initWithName: name identifier: identifier type: deviceType];
3653 return self;
3754}
3855
@@ -64,7 +81,7 @@ - (NSUInteger)hash
6481
6582- (nonnull id )copyWithZone : (nullable NSZone *)zone
6683{
67- ALTDevice *device = [[ALTDevice alloc ] initWithName: self .name identifier: self .identifier];
84+ ALTDevice *device = [[ALTDevice alloc ] initWithName: self .name identifier: self .identifier type: self .type ];
6885 return device;
6986}
7087
You can’t perform that action at this time.
0 commit comments