-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProvisioningProfileInspector.m
95 lines (71 loc) · 3.4 KB
/
ProvisioningProfileInspector.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
//
// ProvisioningProfileInspector.m
// NotifySwiftQuickstart
//
// Created by Viktor Muller on 11/29/16.
// Copyright © 2016 Twilio, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProvisioningProfileInspector.h"
@interface ProvisioningProfileInspector ()
@property (nonatomic, strong) NSDictionary *provisioningProfileInfo;
@end
@implementation ProvisioningProfileInspector
- (instancetype)init {
self = [super init];
if (self != nil) {
self.provisioningProfileInfo = [self loadProvisioningProfileInfo];
}
return self;
}
- (NSDictionary *)dictionary {
NSDictionary *newDictionary = nil;
if (self.provisioningProfileInfo != nil) {
newDictionary = [NSDictionary dictionaryWithDictionary:self.provisioningProfileInfo];
}
return newDictionary;
}
- (APNSEnvironment)APNSEnvironment
{
APNSEnvironment env = APNSEnvironmentUnknown;
if (self.provisioningProfileInfo[@"Entitlements"] != nil) {
NSString *environmentString = nil;
if (self.provisioningProfileInfo[@"Entitlements"][@"com.apple.developer.aps-environment"] != nil) {
environmentString = self.provisioningProfileInfo[@"Entitlements"][@"com.apple.developer.aps-environment"];
} else if (self.provisioningProfileInfo[@"Entitlements"][@"aps-environment"] != nil) {
environmentString = self.provisioningProfileInfo[@"Entitlements"][@"aps-environment"];
}
if ([[environmentString lowercaseString] isEqualToString:@"production"]) {
env = APNSEnvironmentProduction;
} else if ([[environmentString lowercaseString] isEqualToString:@"development"]) {
env = APNSEnvironmentDevelopment;
}
}
return env;
}
- (NSDictionary *)loadProvisioningProfileInfo {
NSDictionary *provisioningProfileInfo = nil;
NSString *provisioningProfilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
if (provisioningProfilePath != nil) {
NSError *error = nil;
NSString *signedDataString = [NSString stringWithContentsOfFile:provisioningProfilePath encoding:NSISOLatin1StringEncoding error:&error];
if (error == nil) {
NSRange startRange = [signedDataString rangeOfString:@"<?xml"];
NSRange endRange = [signedDataString rangeOfString:@"</plist>"];
if ((startRange.location != NSNotFound) && (endRange.location != NSNotFound)) {
NSRange plistRange = NSMakeRange(startRange.location, endRange.location + 8 - startRange.location);
NSString *trimmedString = [signedDataString substringWithRange:plistRange];
NSData *trimmedData = [trimmedString dataUsingEncoding:NSUTF8StringEncoding];
provisioningProfileInfo = [NSPropertyListSerialization propertyListWithData:trimmedData
options:NSPropertyListImmutable
format:NULL
error:&error];
}
}
if ((provisioningProfileInfo == nil) && (error != nil)) {
NSLog(@"Error: %@", error);
}
}
return provisioningProfileInfo;
}
@end