iMessage扩展:从不同的目标获取bundle nil

时间:2017-01-26 14:18:49

标签: ios swift uistoryboard nsbundle imessage-extension

我有一个现有的应用,想要创建一个iMessage扩展。

所以我在我的项目中添加了目标iMessage扩展。现在我想通过容器视图在该扩展中显示我现有的视图。我添加了代码:

let mainBundle = Bundle(identifier:"com.marvel.nearby")
print("MAIN_BUNDLE : \(mainBundle)") // getting nil
let storyboard = UIStoryboard(name: "Main", bundle: mainBundle)
let viewController = storyboard.instantiateViewController(withIdentifier: "MResourcesVC")
self.showViewControllerInContainerView(viewController)
Swift iMessage扩展类 MessagesViewController.swift

但是没有。我该怎么办?

如果这种方式错误,在iMessage扩展中显示viewcontroller的正确方法是什么。

1 个答案:

答案 0 :(得分:2)

您必须将storyboard.storyboard文件添加到目标:

要获得正确的捆绑包,请使用:

Bundle(for: type(of: self))
相关问题