Where to place files in Objective-C and how to read them programmatically with NSBundle

隐身守侯 提交于 2019-12-11 23:10:02

问题


I have been trying to implement SSL Pinning for a hybrid app using a plugin which builds the native code for the required functionality.

Inside the generated native project, the Objective-C code includes the following function to read certificate files (X.509 DER .cer) from the www/certificates location.

// AFSecurityPolicy.m    
+ (NSSet *)certificatesInBundle:(NSBundle *)bundle {
        NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"www/certificates"];
        NSMutableSet *certificates = [NSMutableSet setWithCapacity:[paths count]];

        for (NSString *path in paths) {
            NSData *certificateData = [NSData dataWithContentsOfFile:path];
            [certificates addObject:certificateData];
        }

        return [NSSet setWithSet:certificates];
    }

But due to a known bug in the plugin, this location does not get created automatically (ideally, it should) and I need to manually create the www/certificates location and include my certificate files inside it.

My source file structure looks like below.

ios
|--App
|  |--App.xcodeproj/
|  |--App.xcworkspace/
|  |--Pods/
|  |--public/
|  |--Podfile/
|  |--Podfile.lock
|--capacitor-cordova-ios-plugins
|  |--resources/
|  |--sources
|  | |--AFSecurityPolicy.h
|  | |--AFSecurityPolicy.m
|  | |--......
|  |--CordovaPlugins.podspec
|  |--CordovaPluginsResources.podspec
|  |--CordovaPluginsStatic.podspec
  1. Where should I create this www/certificates directory? (I tried the project root level, plugins folder level, resources level etc., but nothing worked)

  2. Is there something like scopes/ class paths that I need to care about in Objective-C?

  3. Do I need to specify anything in the configuration files for the native app to load those locations?

Disclosure: I am very new to mobile programming and appreciate any sort of help in this regard.

来源:https://stackoverflow.com/questions/56899391/where-to-place-files-in-objective-c-and-how-to-read-them-programmatically-with-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!