BundleUtil.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // BundleUtil.m
  3. // APIExample
  4. //
  5. // Created by zhaoyongqiang on 2022/10/25.
  6. // Copyright © 2022 Agora Corp. All rights reserved.
  7. //
  8. #import "BundleUtil.h"
  9. @implementation BundleUtil
  10. + (NSBundle*)bundleWithBundleName:(NSString *)bundleName podName:(NSString *)podName {
  11. if(bundleName == nil && podName == nil) {
  12. return nil;
  13. } else if (bundleName == nil) {
  14. bundleName = podName;
  15. } else if (podName == nil) {
  16. podName = bundleName;
  17. }
  18. if([bundleName containsString:@".bundle"]){
  19. bundleName=[bundleName componentsSeparatedByString:@".bundle"].firstObject;
  20. }
  21. //没使用framwork的情况下
  22. NSURL *associateBundleURL = [[NSBundle mainBundle]URLForResource:bundleName withExtension:@"bundle"];
  23. //使用framework形式
  24. if (!associateBundleURL) {
  25. associateBundleURL = [[NSBundle mainBundle]URLForResource: @"Frameworks" withExtension:nil];
  26. associateBundleURL = [associateBundleURL URLByAppendingPathComponent:podName];
  27. // associateBundleURL = [associateBundleURL URLByAppendingPathExtension:@"framework"];
  28. NSBundle *associateBunle = [NSBundle bundleWithURL:associateBundleURL];
  29. associateBundleURL = [associateBunle URLForResource:bundleName withExtension:@"bundle"];
  30. }
  31. //生产环境直接返回空
  32. return associateBundleURL ? [NSBundle bundleWithURL:associateBundleURL]: nil;
  33. }
  34. @end