-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathYAProvisioningProfile.m
96 lines (82 loc) · 3.42 KB
/
YAProvisioningProfile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// YAProvisioningProfile.m
// YAProvisioningProfile
//
// Created by Jimmy Arts on 21/02/15.
// Copyright (c) 2015 Jimmy Arts. All rights reserved.
//
#import "YAProvisioningProfile.h"
@interface YAProvisioningProfile ()
@property (nonatomic, strong) NSDictionary *profileDictionary;
@property (readwrite) NSString *name;
@property (readwrite) NSString *teamName;
@property (readwrite) BOOL valid;
@property (readwrite) BOOL debug;
@property (readwrite) NSDate *creationDate;
@property (readwrite) NSDate *expirationDate;
@property (readwrite) NSString *UUID;
@property (readwrite) NSArray *devices;
@property (readwrite) NSInteger timeToLive;
@property (readwrite) NSString *applicationIdentifier;
@property (readwrite) NSString *bundleIdentifier;
@property (readwrite) NSArray *certificates;
@property (readwrite) NSInteger version;
@property (readwrite) NSArray *prefixes;
@end
@implementation YAProvisioningProfile
- (id)initWithPath:(NSString *)path
{
self = [super init];
if (self) {
self.profileDictionary = [self provisioningProfileAtPath:path];
[self processDictionary];
}
return self;
}
- (void)processDictionary
{
self.name = self.profileDictionary[@"Name"];
self.teamName = self.profileDictionary[@"TeamName"];
self.debug = [self.profileDictionary[@"Entitlements"][@"get-task-allow"] isEqualToNumber:@(1)];
self.creationDate = self.profileDictionary[@"CreationDate"];
self.expirationDate = self.profileDictionary[@"ExpirationDate"];
self.devices = self.profileDictionary[@"ProvisionedDevices"];
self.timeToLive = [self.profileDictionary[@"TimeToLive"] integerValue];
self.applicationIdentifier = self.profileDictionary[@"Entitlements"][@"application-identifier"];
self.certificates = self.profileDictionary[@"DeveloperCertificates"];
self.valid = ([[NSDate date] timeIntervalSinceDate:self.expirationDate] > 0) ? NO : YES;
self.version = [self.profileDictionary[@"Version"] integerValue];
self.bundleIdentifier = self.applicationIdentifier;
self.UUID = self.profileDictionary[@"UUID"];
self.prefixes = self.profileDictionary[@"ApplicationIdentifierPrefix"];
for (NSString *prefix in self.prefixes) {
if ([self.bundleIdentifier containsString:prefix]) {
self.bundleIdentifier = [self.bundleIdentifier stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@.", prefix] withString:@""];
}
}
}
- (NSDictionary *)provisioningProfileAtPath:(NSString *)path {
CMSDecoderRef decoder = NULL;
CFDataRef dataRef = NULL;
NSString *plistString = nil;
NSDictionary *plist = nil;
@try {
CMSDecoderCreate(&decoder);
NSData *fileData = [NSData dataWithContentsOfFile:path];
CMSDecoderUpdateMessage(decoder, fileData.bytes, fileData.length);
CMSDecoderFinalizeMessage(decoder);
CMSDecoderCopyContent(decoder, &dataRef);
plistString = [[NSString alloc] initWithData:(__bridge NSData *)dataRef encoding:NSUTF8StringEncoding];
NSData *plistData = [plistString dataUsingEncoding:NSUTF8StringEncoding];
plist = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:nil error:nil];
}
@catch (NSException *exception) {
NSLog(@"Could not decode file.\n");
}
@finally {
if (decoder) CFRelease(decoder);
if (dataRef) CFRelease(dataRef);
}
return plist;
}
@end