美文网首页ios开发
在Xcode项目中使用Bundle

在Xcode项目中使用Bundle

作者: 贪恋冬天的幸福 | 来源:发表于2019-03-04 15:30 被阅读0次

选择macOS->Framework & Library->Bundle,

在项目的侧边栏出现PROBundle文件夹,在Products下出现PROBundle.bundle,在TARGETS下出现PROBundle,如下图:

选中TARGETS下的PROBundle,在Build Settings下将Base SDK改为iOS,

将 COMBINE_HIDPI_IMAGES 改为NO,

选中TARGETS下的PRO_WIRELESS,在Build Phases下的Target Dependencies下点击+,添加PROBundle,

然后再Build Phases下点击左上角 + ,添加

在Run Script下添加如下脚本:cp -R ${BUILT_PRODUCTS_DIR}/PROBundle.bundle ${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app

在项目中使用这个Bundle下的资源:

    NSBundle*mainBundle = [NSBundle mainBundle];

    NSString *PROBundlePath = [[mainBundle resourcePath] stringByAppendingPathComponent:@"PROBundle.bundle"];

    NSBundle*PROBundle = [NSBundle bundleWithPath:PROBundlePath];

    NSString *imagePath = [PROBundle pathForResource:@"common_discover_destination_flightTo" ofType:@"png"];

    UIImage*image = [[UIImage alloc]initWithContentsOfFile:imagePath];

参考文章:https://www.jianshu.com/p/5da2fa27d823

相关文章

网友评论

    本文标题:在Xcode项目中使用Bundle

    本文链接:https://www.haomeiwen.com/subject/bxsbuqtx.html