【问题标题】:Loading iOS Bundle on real device在真实设备上加载 iOS Bundle
【发布时间】:2016-05-22 17:54:01
【问题描述】:

我有一个插件包,应该加载到我的应用程序中。 当我在 iOS 模拟器上运行应用程序时,捆绑包已正确加载,但是当我重新编译项目以便在我的真实设备上运行应用程序时,我收到以下错误:

Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter): no suitable image found.  Did find:
/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter: mmap() error 1 at address=0x022CF000, size=0x00008000 segment=__TEXT in Segment::map() mapping /var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter" UserInfo={NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter, NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedDescription=The bundle “grandmaAdapter” couldn’t be loaded because it is damaged or missing necessary resources., NSDebugDescription=dlopen_preflight(/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter): no suitable image found.  Did find:
/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter: mmap() error 1 at address=0x022CF000, size=0x00008000 segment=__TEXT in Segment::map() mapping /var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter, NSBundlePath=/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle}

基本上我做的是:

-定义文档目录中的文件路径

NSString *bundleName = [NSString stringWithFormat:@"%@.bundle", bundle];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePath = [documentsDirectory stringByAppendingPathComponent:bundleName];

-然后加载捆绑包

NSBundle *plugin = [[NSBundle alloc] initWithPath:filePath];

NSError *err;
if(![plugin loadAndReturnError:&err]) {
    // err contains error info
} else {
    // bundle loaded properly

}

这里我得到了上面的错误

有人可以帮我吗?谢谢

已解决

该错误与缺少代码签名有关。 如本文所述:http://ddeville.me/2014/04/dynamic-linking/ 插件需要签名才能在真实设备上加载,使用以下命令:

codesign --sign "iPhone Developer" --force --verbose=4 myPluginName.plugin

【问题讨论】:

  • 你是如何将包加载到模拟器中的?如果以编程方式,请显示您的代码。
  • 我已经用我的代码编辑了
  • 也许问题可能与目录访问权限问题有关?(在真实设备上)。即使消息报告捆绑损坏或丢失数据..
  • 这与权限问题无关——我在尝试这个时遇到了同样的错误。我现在不在电脑前,但是今晚我会看我的代码,给你一个明确的答案!
  • 提前致谢!

标签: ios xcode


【解决方案1】:

loadAndReturnError: 之前,您的捆绑加载代码看起来不错。在弄清楚如何加载捆绑包时,我遇到了同样的错误。

我知道这听起来违反直觉,但您不需要调用该方法。相反,请尝试以下方法。

我希望这会有所帮助!如果您仍然收到错误,则问题可能与您创建捆绑包的方式有关。

UIView *resourceView = nil;

NSBundle *resourceBundle = [NSBundle bundleWithPath:resourcePath];

@try {
    //Try to load the NIB from the given bundle
    resourceView = [[resourceBundle loadNibNamed:nibName owner:owner options:nil] lastObject];
}
@catch (NSException *exception) {
    //do nothing - will search in main bundle
}

//If loading from the given bundle failed, try loading from the main bundle
if (!resourceView) {
    NSBundle *resourceBundle = [NSBundle mainBundle];

    @try {
        resourceView = [[resourceBundle loadNibNamed:nibName owner:owner options:nil] lastObject];
    }
    @catch (NSException *exception) {
        //do nothing - will return nil, indicating an error occurred
    }
}

return resourceView;

注意事项

在走这条路之前,请务必注意,您真正需要创建捆绑包的唯一原因是添加 XIB 文件。对于任何其他资产,例如图像、音频或视频文件,只需将文件压缩并从服务器位置下载并解压缩到您的文档目录中就足够了(而且更简单)。

如果您需要更新 XIB 使用的资产,那么最好以编程方式加载这些资产,而不是在 XIB 中设置它们(或在 XIB 中设置默认值)。这样一来,您就可以从使用捆绑方法中解放出来,而是使用上面提到的压缩存档。

【讨论】:

  • 感谢 Sheamus,但这不是我需要的。我正在开发一个应用程序,它可以从远程服务器下载插件并在运行时加载代码。
  • @davideb 你是如何创建捆绑包的?
  • 创建一个Bundle项目(扩展名.plugin)并将Base SDK更改为最新的iOS
  • 无论如何,奇怪的是相同的代码在模拟器上运行良好,而在我的真实设备上似乎缺乏资源(依赖项?)..
  • @davideb 啊,我明白了。我不必那样做。我认为这是因为我的包中没有可执行文件,只有资产。
猜你喜欢
  • 2016-02-04
  • 2014-09-22
  • 1970-01-01
  • 1970-01-01
  • 2013-06-30
  • 2014-10-07
  • 2017-02-01
  • 2014-11-10
  • 2021-07-22
相关资源
最近更新 更多