apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

feat: support multiple provisioning profiles #956

Closed HarelM closed 1 year ago

HarelM commented 3 years ago

Platforms affected

ios

Motivation and Context

When using a plugin that creates a new target it is currently impossible to sign it using cordova command line. See issue #953

Resolves #953

Description

Added the option to set multiple provisioning profiles only in the build.json file.

Testing

I've tested this code on the app I'm writing.

Checklist

HarelM commented 3 years ago

anyone?

timbru31 commented 3 years ago

Can you name the issues this PR would close? I see some references but not sure if any of those should be closed with this PR?

HarelM commented 3 years ago

@timbru31 Updated the name, hope this is what you intended.

HarelM commented 3 years ago

@timbru31 done! Thanks for the review. Let me know when a new version is available. :-)

HarelM commented 3 years ago

@timbru31 anything else that I need to do? Can this be merged?

HarelM commented 3 years ago

Any one? Can this be merged? I would really like to migrate of my fork and to this repo, hopefully using a npm version, but a git commit will also do as long as I'm not using my getting-out-dated-fork... :-)

HarelM commented 3 years ago

Anything I can do in order to move this request forward?

brodybits commented 3 years ago

I would recommend that you follow up with us on the mailing list or on Slack.

HarelM commented 3 years ago

@brodybits I tried slack and didn't got any response to my post... I'm currently using this my fork in a production app which behaves as expected, so I'm guessing this is as good as it gets in terms of testing. And in general I don't think this change is a breaking change as I wrote it with backwards compatibility in mind... I really hoped it wouldn't take so much time to merge a pull request... :-(

ollm commented 2 years ago

I can confirm that @HarelM solution works, I would appreciate if the pull request it's merged.

Also the build.json documentation should be updated: https://cordova.apache.org/docs/en/10.x/guide/platforms/ios/#using-buildjson

Current usage in build.json (And it still works):

{
    "ios": {
        "release": {
            "codeSignIdentity": "iPhone Distribution",
            "developmentTeam": "XXXXXXX",
            "packageType": "app-store",
            "provisioningProfile": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "iCloudContainerEnvironment": "Production",
            "buildFlag": [
                "-UseModernBuildSystem=0",
                "EMBEDDED_CONTENT_CONTAINS_SWIFT = YES",
                "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=NO",
                "LD_RUNPATH_SEARCH_PATHS = \"@executable_path/Frameworks\""
            ]
        }
    }
} 

Multiple profile usage in build.json whith @HarelM solution:

{
    "ios": {
        "release": {
            "codeSignIdentity": "iPhone Distribution",
            "developmentTeam": "XXXXXXX",
            "packageType": "app-store",
            "provisioningProfile": {
                "app.package.name": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "app.package.name.NotificationService": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
            },
            "iCloudContainerEnvironment": "Production",
            "buildFlag": [
                "-UseModernBuildSystem=0",
                "EMBEDDED_CONTENT_CONTAINS_SWIFT = YES",
                "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=NO",
                "LD_RUNPATH_SEARCH_PATHS = \"@executable_path/Frameworks\""
            ]
        }
    }
} 
jlews commented 2 years ago

I'm currently really blocked by this. Does anyone know of a workaround that will allow me to edit the exportOptions.plist file after cordova generates it, but before the archive is exported? From what I can tell, this all happens inside the cordova compile command and there's no hook that will allow me to do this.

HarelM commented 2 years ago

You can fork cordova-ios and apply this change if you want the latest version or you can take my fork and use it in package.json as a git reference and not use the official vesion.

CodeWithOz commented 2 years ago

@HarelM can you confirm that the multiple profile usage of build.json suggested by @ollm works with your fork? I've tried using it for my multiple profiles (main app and share extension) but the build step fails with the error error: "ShareExt" requires a provisioning profile with the App Groups feature. Select a provisioning profile in the Signing & Capabilities editor. (in target 'ShareExt' from project '{Project Name}'). Of course the ShareExt provisioning profile actually exists and is specified in the build.json as @ollm suggested, so that means the build step is not finding it correctly.

HarelM commented 2 years ago

I can't confirm this anymore unfortunately. Since this was ignored for far too long I have found a solution that does not use the shareext plugin and thus are not using my fork and do not need two provisioning profiles anymore... Sorry... Maybe @ollm is still using it and can confirm this is still valid. As a side note, it might be that the provisioning profile exists but lack the App Group features...? Sorry I can't truly help. It used to work when I used it back then...

CodeWithOz commented 2 years ago

Okay thanks for confirming. Can you share the alternate solution you found please? And on my end yes I've confirmed that the profile has the App Groups feature.

ollm commented 2 years ago

Yes, I still use them to display images in push notifications

First I recommend that you check if the two or more profiles appear in the file ./projectName/platforms/ios/exportOptions.plist after build, I build using the command line like this cordova build ios --device --realese --buildConfig build.json.

Like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>compileBitcode</key>
    <false/>
    <key>method</key>
    <string>app-store</string>
    <key>iCloudContainerEnvironment</key>
    <string>Production</string>
    <key>teamID</key>
    <string>XXXXXX</string>
    <key>provisioningProfiles</key>
    <dict>
      <key>app.package.name</key>
      <string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
      <key>app.package.name.NotificationService</key>
      <string>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</string>
    </dict>
    <key>signingStyle</key>
    <string>manual</string>
    <key>signingCertificate</key>
    <string>iPhone Distribution</string>
  </dict>
</plist>

If the profiles don't appear, open the files ./projectName/platforms/ios/cordova/lib/build.js and ./projectName/platforms/ios/cordova/build and check that the @HarelM changes are present, if they are not you can edit these same files manually or reinstall the cordova-ios fork.

HarelM commented 2 years ago

I basically associate the files and urls with my app, nothing else. I use some plugins for that, mainly web intent and deep links. You can see my code in the following places: iOS hack: https://github.com/IsraelHikingMap/Site/blob/be555a25e37b6d274d11f74a998986a5b27881a1/IsraelHiking.Web/src/index.html#L137 The main service I use: https://github.com/IsraelHikingMap/Site/blob/be555a25e37b6d274d11f74a998986a5b27881a1/IsraelHiking.Web/src/application/services/open-with.service.ts And a lot of definitions in the config.xml: https://github.com/IsraelHikingMap/Site/blob/be555a25e37b6d274d11f74a998986a5b27881a1/IsraelHiking.Web/config.xml

CodeWithOz commented 2 years ago

@ollm thanks for the additional info, I'll check to see if that fixes my problem.

@HarelM thanks a lot for sharing. I don't use angular so please confirm if this is a correct description of your workaround: you use the config.xml file to specify all the file types that your app can receive from a share, and when the share happens (in the form of a deep link), you parse the shared information and route to the appropriate part of your app. Is that accurate?

If it is, I have one more question: did you have to take any additional steps to make your app a share target for those file types, or was it sufficient to only specify them in the config.xml file?

ollm commented 2 years ago

Something that I have forgotten to comment on is that I think it is necessary to have Automatically manage signing disabled (That's how I have it), although I'm not entirely sure.

Profile

HarelM commented 2 years ago

@CodeWithOz in general, yes. The index.html is not related to angular and is super important for iOS. I use other plugins to handle intent in android, I don't remember now exactly which one, you can check my package.json file...

SteveGilvarry commented 1 year ago

Can I ask what is preventing merging this and what I can do to assist to move it forward? Would be very useful for my notification service extension allowing me to build via command line, maybe not everyones use case but it works and doesn't impact those not using them.

HarelM commented 1 year ago

BTW, I'm currently migrating to Capacitor where this is not longer a concern as you simply create the exportOptions.plist file, check it in and use it how ever you see fit. I did returned to this code in order to understand how to write the file and the command line to archive and export in xcode, but other than that this is no longer needed :-)

Makishima commented 1 year ago

Could anyone say if there any workaround to use several profiles with cordova build?

HarelM commented 1 year ago

This was my workaround, it didn't got merged, so I don't think there's another option besides building this manually from xcode...

erisu commented 1 year ago

Can you rebase against the main branch?

The PR has changes to file bin/templates/scripts/cordova/build which has been removed in the main branch. This file should be deleted.

HarelM commented 1 year ago

This PR is two years old now. I can't say I fully remember what I did there although the change wasn't big, so in theory I should be able to remember. Having said that, I no longer use Cordova as I migrated to Capacitor, so feel free to copy the code and use it, or create a different PR. Sorry...

ollm commented 1 year ago

I have send a pull request with the changes on the master branch https://github.com/apache/cordova-ios/pull/1251, I can confirm that these changes work on cordova-ios version 6.2.0, but I haven't tested it on the master version yet.

Could you tell me how can I install cordova-ios master version in my project to test it?

erisu commented 1 year ago

@ollm any of these variants should work.

If you want to install the main branch of your fork, on github.

Note: The path contains ollm, which represents your fork of the repo. If you want to use anyone elses fork, just update the path.

Or you can install from a local directory.

ollm commented 1 year ago

@ollm any of these variants should work.

If you want to install the main branch of your fork, on github.

  • cordova platform add github:ollm/cordova-ios
  • cordova platform add git@github.com:ollm/cordova-ios.git
  • cordova platform add https://github.com/ollm/cordova-ios.git

Note: The path contains ollm, which represents your fork of the repo. If you want to use anyone elses fork, just update the path.

Or you can install from a local directory.

  • cordova platform add /path/to/cordova-ios

Thanks, I have tested the changes and it works perfectly with multiple provisioning profiles (I have tested with 2 profiles)

If there is anything else I need to do to get the branch merged, please let me know (eg documentation)