Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I package entire iOS app as a Framework?

I have an app implemented in native iOS (Swift). There is a web version of the app as well. A client wants to embed my app to its own app and suggested I use an iFrame and load the web version. I understand this is a tricky solution as Apple might reject the app for not using native implementation.

What I want to ask is if there is a way to package my app entirely as a Framework and load it that way (app size is fairly big, with several viewControllers and functionality).

I understand that I won't have access to App-load functions like the AppDelegate.

Also what happens if my app has Library dependencies ? (such as Alamofire)

Any other things I should be concerned about ?

Thank you

like image 289
PoolHallJunkie Avatar asked May 03 '19 09:05

PoolHallJunkie


1 Answers

There are obviously a lot of options around this as far as design/approach.

I've done this multiple times (with apps live on the app store) and really it's just like developing any Framework.

First: AppDelegate. The easy way around this is to have the app's AppDelegate subclass your Framework's AppDelegate:

@UIApplicationMain class ParentAppDelegate: FrameworkAppDelegate { }

Just make sure the App calls super on all the relevant methods.

Second: Dependencies. This is probably the most annoying part since Frameworks can't embed other frameworks. But you still have a few easy options:

  1. Have the enclosing app embed the needed framework
  2. Add the sources of the needed framework directly to your framework.
  3. Use a dependency manager (e.g. cocoapods) that takes care of this for you.

Other Concerns: One trap you can easily run into is working with Bundles. Anytime you dynamically load images/strings/IB references/etc. you will need to specify you're using the Framework's bundle, as at times it can default to using the app's bundle. The easiest way to do this is with this init e.g. Bundle(for: self.self)

Also keep in mind that the settings in info.plist and entitlements your framework needs will need to be added by the parent app.

General Comments on Approach: My advice (take it or leave it ☺️) would be caution around simply adding your full application to a client's application. Aside from IP and App-Review concerns, it can result in adding a lot of complexity or a fork of your current application to support it, making future maintenance a hassle.

Instead I would recommend putting only the portions of the application your client requires into a separate framework that both you and your client use for your separate applications.

like image 163
GetSwifty Avatar answered Nov 20 '22 15:11

GetSwifty