use correct asset name for ios platform if we are running capacitor

This commit is contained in:
uf200387
2023-03-05 00:37:17 +08:00
parent 0c26ada847
commit f6adf1e920

View File

@@ -156,15 +156,14 @@ static NSArray * AFPublicKeyTrustChainForServerTrust(SecTrustRef serverTrust) {
@implementation SM_AFSecurityPolicy
+ (NSSet *)certificatesInBundle:(NSBundle *)bundle {
NSArray* paths = @[];
for(NSString* dir in @[@"www", @"public"]) {
NSArray* certificatePaths = [bundle pathsForResourcesOfType:@"cer" inDirectory: [NSString stringWithFormat:@"%@/certificates", dir]];
if(certificatePaths.count > 0) {
paths = certificatePaths;
break;
}
NSString* assetDir = @"www";
Class capacitorPluginClass = NSClassFromString(@"CAPPlugin");
if(capacitorPluginClass != nil) {
// we are running on capacitor and its assets dir is 'public'
assetDir = @"public";
}
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory: [NSString stringWithFormat:@"%@/certificates", assetDir]];
NSMutableSet *certificates = [NSMutableSet setWithCapacity:[paths count]];
for (NSString *path in paths) {
@@ -179,7 +178,7 @@ static NSArray * AFPublicKeyTrustChainForServerTrust(SecTrustRef serverTrust) {
static NSSet *_defaultPinnedCertificates = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSBundle *bundle = [NSBundle mainBundle];
_defaultPinnedCertificates = [self certificatesInBundle:bundle];
});