Can you run an iOS app within another iOS app with Xcode sub projects?

大城市里の小女人 提交于 2019-12-25 04:53:07

问题


I have recently purchased some source code of a mini game that I wish to include in my current complex application. However I am having difficulties actually implementing the mini game into my app. Initially I tried copying the source files into my project but stumbled across problems with having two separate app delegates. Is it possible to have two separate delegates?

Another method I though about was by adding the mini game project as an Xcode subproject. However I'm not sure if this is possible, and if it is, how would I go about doing so? If you know a better method, I would appreciate greatly any sort of help.

Thank you.


回答1:


You're going to need to do one of the following, depending on your specific needs and on whatever licenses may apply to this source code that you purchased:

  • Build a new app and copy some or all of the mini-game's source code into your app (or add that code as a subproject, but read on for more on that).
  • Take the existing mini-game's source code and modify it until it becomes what you need.

In both cases it's going to involve some understanding of the incoming source code, including its structure and operations. The best source for this information is probably the seller.

To answer some specific questions raised:

Can you run an iOS app within another iOS app with Xcode sub projects?

No. You can't run one iOS app inside of another, full stop. You can merge the source code from more than one app into one new app if you understand the code well enough.

I ... stumbled across problems with having two separate app delegates. Is it possible to have two separate delegates?

Not two app delegates. The app delegate is specifically the delegate object of the shared, singleton UIApplication object. Code-wise, the app delegate is the value of [[UIApplication sharedApplication] delegate]. That's not an array or other collection-- it's a single object. Most likely you're going to have to look at what the two app delegate classes do and merge their functionality into one.

(Italics above because "delegate" is a pattern used in many places in iOS development. You may well have many objects that are a delegate of one kind or another, but only one will be the app delegate).

Another method I though about was by adding the mini game project as an Xcode subproject. However I'm not sure if this is possible, and if it is, how would I go about doing so?

This is possible but it's not likely to be a solution to your problem. Subprojects are commonly used for external dependencies from different sources, like libraries or frameworks (e.g. if you were using AFNetworking you might choose to make it a subproject). That might be a good idea in your case (or might not, it's impossible to say without a lot more detail). But on its own it doesn't fix the problem of how to get this mini-game's functionality into your app.




回答2:


Copy the code over the mini game to your project, it will be a pain but it's the best way. The other option (which may not be possible) that I have not tested would be use container views to tap into the mini game classes.



来源:https://stackoverflow.com/questions/20578278/can-you-run-an-ios-app-within-another-ios-app-with-xcode-sub-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!