Skip to content

Commit 70a9594

Browse files
committed
Adds ALTDevice.type + ALTDeviceType enum
Supports iPhones, iPads, and Apple TVs.
1 parent 5905038 commit 70a9594

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

AltSign/Model/Apple API/ALTDevice.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@
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+
1121
NS_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

AltSign/Model/Apple API/ALTDevice.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
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

0 commit comments

Comments
 (0)