codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.67k stars 400 forks source link

iOS App Extension Support #3427

Open shannah opened 3 years ago

shannah commented 3 years ago

App extensions are like separate apps embedded within the main app bundle on iOS. They have their own App ID and need their own provisioning profile and entitlements. I plan to add support for adding app extensions by using the the following process:

In maven build:

  1. When performing iOS build, it will look for directories of the form ios/app_extensions/*. These directories are app extension projects that have already been created in Xcode. 1.1. For each of these appextension projects, it zips them with the extension ".ios.appext", and includes them in the bundle that is sent to the build server.
  2. Also, when performing iOS build, it will look for provisioning profiles in the common/iosCerts directory, and it will include these in the bundle that is sent to the build server.

On build server

  1. Any files with ios.appext it finds in the bundle, it will extract and add to the main project as an app extension.
  2. Any provisioning profiles it finds in the bundle, it will add to the project's keychain so that they can be referenced during build.
  3. It provides necessary wiring so that the project will build with the app extensions.

In Maven "Generate Xcode Project" build target

It will perform same steps as build server to inject the share extension into the project. It may not do anything with provisioning profiles, and rather let Xcode take care of this, like it does with the main project.

In Certificate wizard

If the user chooses to generate provisioning profile, then it will look in the ios/app_extensions/ directory to find any app extensions that need provisioning profiles, and it will generate profiles for them also, and save them in the common/iosCerts directory.

javieranton-zz commented 3 years ago

Just trying to understand if this applies to my use case. When you say extension, you mean things like Share Extensions, Notification Extensions, right?

I currently use a notification and a share extension. However, I also include a UserDefault reference in each of these (not sure if this will cause any issue)

Anyway, hope a blog post will be written on this so that the process can be easily understood

Thanks

shannah commented 3 years ago

How are you currently building your app with a share extension? Do you build with sources then add the extension afterward using Xcode?

javieranton-zz commented 3 years ago

Yes, every time I build with sources, then open with xcode, then add the extensions (file -> new target, etc).

Then I add the UserDefaults capability to each extension (I use that to talk between app and extensions), change the extension's version to match the main app's version, and select compatibility with iOS 10

In the case of the Notification Extension, I replace the .m file with my own

In the case of the Share Extension, I replace the .m file with my own, and then also modify the plist file to filter the appropriate shared types

shannah commented 3 years ago

I see. So after I implement what I'm proposing, you would only need to go through your process once. Then you would save your Xcode extension directory inside your Codename One app project under the ios/app_extensions directory, and the build server would link it into the project automatically.

javieranton-zz commented 3 years ago

That sounds awesome! Thanks a lot for this

There is another use case that might be useful in the future. I also happen to replace the app delegate's .m code with my own after each time I build. This is useful because I implement my own notification extension so I need to modify the code in a few places. It would be amazing to be able to overwrite the app delegate's code as well, but I know it's not the focus of this, just sharing