2017-03-02 908 views
2

我想创建一个静态框架,它将使用一些图像在其视图中显示。我通过在sdk项目中添加目标,从XCode创建了一个MyFrameworkBundle.bundle。在捆绑中添加了所有图像并创建了捆绑,并为该目标提供了捆绑标识my.frameworkbundle。 我现在想取回我的框架,像束以下:NSBundle bundleWithIdentifier为静态框架和资源包返回null

NSBundle * mybundleRef = [NSBundle bundleWithIdentifier:@"my.frameworkbundle"]; 

然后我把这些框架和资源包中的另一个项目,并试图与上述线路运行功能。它总是返回null。即使我试图获取像上面的代码框架,即:

NSBundle * mybundleRef = [NSBundle bundleWithIdentifier:@"my.framework"]; 

这也给了我null。但是如果我将这个框架从静态变为动态,它总会给我提供正确的包装。 因为我打算在Unity中使用它,所以我不想使用动态框架来避免后期处理脚本。

我也试过下面的代码:

NSString *bundleString =[[NSBundle mainBundle] pathForResource:@"MyFrameworkBundle" ofType:@"bundle"]; 
NSBundle * PlayCacheBundle = [NSBundle bundleWithPath:bundleString]; 

,但它给错误

没有合适的图像发现

系统细节:

  • 的Xcode:8.2 .1
  • 的MacOS:10.12(塞拉利昂)

回答

0

使用此指定dynmically捆绑:对答案 我已经测试此代码与我的框架

NSBundle *mybundleRef = [NSBundle bundleForClass:[self class]] 
+0

感谢为类仅在框架不是资源bundle 'NSBundle * myBundleRef = [NSBundle bundleForClass:[MyFrameworkClass class]];' 'NSLog(@“Bundle Result:%@”,myBundleRef);' 但是作为回报,它给了我一个NSBundle,项目(我导入框架的项目),而不是我的框架扫。我也尝试使用这个包来获取图像 'UIImage * Imageref = [UIImage imageNamed:@“msg.png”inBundle:myBundleRef compatibleWithTraitCollection:nil];' 它在ImageRef中返回null。 –