您好,欢迎来到叨叨游戏网。
搜索
您的当前位置:首页iOS获取某个组件bundle

iOS获取某个组件bundle

来源:叨叨游戏网

Swift获取某个bundle

/// 根据podName找到bundle
func ext_SwiftBundle(podName:String) -> Bundle? {
    let bundlePath:String? = ext_SwiftBundlePath(podName:podName)
    return Bundle(path: bundlePath ?? "")
}
/// 根据podName找到bundlePath
func ext_SwiftBundlePath(podName:String) -> String? {
    var bundlePath: String?
    for bundle: Bundle in Bundle.allBundles {
        bundlePath = bundle.path(forResource: podName, ofType: "bundle")
        if bundlePath != nil && bundlePath?.count != 0 {
            return bundlePath
        }
    }
    
    for bundle: Bundle in Bundle.allFrameworks {
        bundlePath = bundle.path(forResource: podName, ofType: "bundle")!
        if bundlePath != nil && bundlePath?.count != 0 {
            return bundlePath
        }
    }
    return bundlePath
}

Object-C获取某个bundle

/// 根据podName找到bundlePath
+ (NSString*)jdd_bundlePathForPod:(NSString*)podName
{
    // search all bundles
    for (NSBundle* bundle in [NSBundle allBundles]) {
        NSString* bundlePath = [bundle pathForResource:podName ofType:@"bundle"];
        if (bundlePath) {
            return bundlePath;
        }
    }
    
    // search all frameworks
    for (NSBundle* bundle in [NSBundle allFrameworks]) {
        NSString* bundlePath = [bundle pathForResource:podName ofType:@"bundle"];
        if (bundlePath) {
            return bundlePath;
        }
    }
    
    // some pods do not use "resource_bundles"
    // please check the pod's podspec
    return nil;
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.net 版权所有 湘ICP备2024080961号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务