- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在主 Xcode 项目上按 UIButton 并运行项目列表中的子项目。这可能吗 ?这是我从 MainViewController
到我的主项目的代码:
import UIKit
class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func playSubproject(_ sender: UIButton) {
// here I want to run the SubProject O2App.xcodeproj
// More exactly I want to run a method from that subproject which is in ViewController.swift and is named startUnity().
}
}
这是我的 ViewController 子项目的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var backgroundImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
backgroundImageView.isHidden = false
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.startUnity()
NotificationCenter.default.addObserver(self, selector: #selector(handleUnityReady), name: NSNotification.Name("UnityReady"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleUnityPlayHologram(_:)), name: NSNotification.Name("UnityPlayHologram"), object: nil)
}
}
}
这是来自子项目的 AppDelegate,其中我有函数 startUnity
。如果可能的话,我想将此 startUnity
函数调用到我的主项目中。这是代码:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var application: UIApplication?
@objc var currentUnityController: UnityAppController!
var isUnityRunning = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.application = application
unity_init(CommandLine.argc, CommandLine.unsafeArgv)
currentUnityController = SVFUnityPluginAppController()
currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)
// first call to startUnity will do some init stuff, so just call it here and directly stop it again
startUnity()
stopUnity()
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
if isUnityRunning {
currentUnityController.applicationWillResignActive(application)
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
if isUnityRunning {
currentUnityController.applicationDidEnterBackground(application)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
if isUnityRunning {
currentUnityController.applicationWillEnterForeground(application)
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if isUnityRunning {
currentUnityController.applicationDidBecomeActive(application)
}
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
if isUnityRunning {
currentUnityController.applicationWillTerminate(application)
}
}
public func startUnity() {
if !isUnityRunning {
isUnityRunning = true
currentUnityController.applicationDidBecomeActive(application!)
}
}
public func stopUnity() {
if isUnityRunning {
currentUnityController.applicationWillResignActive(application!)
isUnityRunning = false
}
}
}
这是我的主项目和子项目的屏幕截图:
编辑:
在我的 MainProject 中,我进入“build设置”,并在“标题搜索路径”中使用以下代码行设置子项目中所有类的路径: $(inherited) "$(SRCROOT)/O2App/O2App/Unity""$(SRCROOT)/O2App/O2App/Unity/Classes""$(SRCROOT)/O2App/O2App/Unity/Classes/Unity""$(SRCROOT)/O2App/O2App/Unity/Classes/Native""$(SRCROOT)/O2App/O2App/Unity/Libraries""$(SRCROOT)/O2App/O2App/Unity/Libraries/libil2cpp/include"。现在,在 MainViewController 中,我导入 O2App,现在我可以访问所有这些类。但是当我尝试从该类调用方法时,出现错误。这是我按下按钮时尝试在函数中执行的操作:
@IBAction func playSubproject(_ sender: UIButton) {
ViewController().viewDidLoad()
}
这是错误:
Undefined symbols for architecture arm64:
"type metadata accessor for O2App.ViewController", referenced from:
RGA_MainProject.MainViewController.playSubproject(__ObjC.UIButton) -> () in MainViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
最佳答案
您需要在子项目中创建一个框架。然后,您可以在主项目中导入该框架并运行子项目中的代码。这是您问题的答案。
仅供引用。我发现您正在与 Unity 打交道。好消息 - 可以将 Unity 嵌入到框架中,并且通常您的思考方式是正确的。坏消息 - 您的实现存在错误并且总体上很复杂。这个问题无法涵盖这个主题。
关于ios - 如何从子项目调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52298478/
我正在开发几个不同的 Joomla 附加组件,但希望将它们保留为单独的 git 存储库,因为它们有不同的开发团队(甚至组织)。但是,我也想将它们作为共享相同 Joomla 基础(被 .gitignor
最近,由于行销人员的要求,我已将Optimobile SDK添加到我正在工作的项目中。 在将其添加并在设备上安装新的apk之后。我注意到,我的应用程序中添加了两个新权限,即无需用户交互即可发送SMS的
我遇到了gradle plugin帮助我处理带点的属性名称。像这样使用时,它在单个项目中工作正常: apply plugin: 'config' buildscript { repositor
我很难设置一组相互依赖的相关 Maven 项目。 这是我的简化案例: pom.xml -- parent pom \base\ pom.xml src\main\java\Ba
我正在研究 Apache Ant 项目的发展,以使用 Gradle 对其进行编译,并且我有不同的子项目集。 我的目标是将主项目的输出用作某些子项目的依赖项。全局配置如下: MainProject:
对于每个用户帐户,我尝试计算他们今天有多少个事件。 我的数据结构如下: accounts - { "-KaxcGWx1-a8s7dhsjhsd" : { "name" : "Bill", "ev
我有两个项目: workspace Project1 |--build.gradle |--settings.gradle |--Subproject1 | |--build.
我们有一个 Maven 多模块项目,我们希望逐步迁移到一个 gradle 项目。 对于初学者,我只想将几个子项目迁移到 gradle,但将它们作为子项目保留到父 maven-project 构建。 有
我的 gradle 项目结构如下所示: geode-core geode-lucene extensions/geode-modules extensions/geode-modules-sessio
我有一个基于 CMake 的项目,具有以下“设计”: add_subdirectory(first_lib) add_subdirectory(second_lib) add_subdirectory
我创建了一个表单,其中有 2 个部分,一个是标题(父级),另一个是子级。在标题部分,我创建了一个字段,如项目(下拉),如 netsuite、SFDC 等,在子部分,我创建了另一个字段,如子项目。当我根
我正在创建一个新的应用程序 MyApp,我决定将应用程序的某些部分放在一个单独的框架 MyFramework 中,而不是应用程序本身,以使其可重用在其他项目中。该框架有自己的项目 (MyFramewo
想象一个包含多个组件的整体项目: 基本 我 网络 app-a app-b app-c 现在,假设 web 依赖于依赖于 basic 的 io,所有这些东西都在一个 repo 中,并且有一个 CMake
我有一个 SBT 项目,特别是 Play Framework 2.1 项目,它在配置中指定了许多子项目。编译时依赖项似乎工作正常,但“清理”似乎只清理当前选定的项目,不包括其依赖项。有什么方法可以清理
我有一个工作的多模块 Play 2.2 应用程序,它的组织方式是这样的...... myApp + app + conf + project + build.propertie
我无法理解模块和子项目之间的区别。有什么区别,哪个应该用于模块应用程序。 最佳答案 使用这两种方法,您都可以单独编译、运行和测试代码。 使用子项目,您可以共享设置,并且它通过源代码连接到依赖它的项目:
我有一个使用 Scala 2.10 的项目和一个使用 Scala 2.11 的项目。它们依赖于一个可以同时编译的通用项目。 lazy val foo = (project in file("foo")
如何让 gradle 克隆一个 git 存储库(到当前存储库的子存储库)并将其构建为子项目? 目前我有以下内容: settings.gradle: include 'contrib/dependenc
我在我的 gradle 项目中添加了一个子项目,现在每当我执行目标 check ,它还在我的子项目上运行测试。 我希望我可以运行 check - 主项目上的任务,将其指定为绝对任务 gradle :c
假设您有 2 个 gradle 项目。第一个是一个包含 2 个 java 子项目的多项目: rootProject :my:subProject1 :myother:subProjec
我是一名优秀的程序员,十分优秀!