customerio / customerio-expo-plugin

MIT License
11 stars 9 forks source link

Enabling `richPush: true` for iOS causes build errors #35

Closed euc-callum closed 1 year ago

euc-callum commented 1 year ago

Hi, I'm a little confused by the following build error I'm receiving when running iOS builds with richPush:true in the app.config.ts.

/Users/expo/workingdir/build/ios/<projectname>.xcodeproj: error: No profiles for '<identifier>.richpush' were found: Xcode couldn't find any iOS App Development provisioning profiles matching '<identifier>.richpush'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'NotificationService' from project '<projectname>')

It appears to have a resolution suggested in the build failure - but please could you explain what is occurring here so I understand what I am enabling?

Thanks!

euc-callum commented 1 year ago

As requested via email, here are the relevant parts of our app.config.ts with some identifying information redacted:

export default (): ExpoConfig => {
  const appEnv = process.env['APP_ENV'] ?? 'development';
  const brand = process.env['BRAND'] ?? '<default-brand>';
  const isLocalBuild = !process.env['EAS_BUILD'];

  if (!isSupportedBrand(brand)) {
    throw new Error('Only <default-brand> builds are supported at the moment');
  }

  let appIdentifier = '<company-identifier>.<company-name>.<default-brand>';
  let name = '<brand-name>';

  if (!isSupportedEnv(appEnv)) {
    throw new Error(`APP_ENV must be either "development" or "production"`);
  }

  if (appEnv === 'development') {
    appIdentifier += '.dev';
    name += ' (Dev)';
  }

  return {
    name,
    slug: brand,
    version: '<version>',
    owner: '<company-name>',
    orientation: 'portrait',
    icon: `./assets/images/${brand}-${appEnv}-icon.png`,
    scheme: '<brand-name>',
    userInterfaceStyle: 'automatic',
    backgroundColor: '<colour>',
    splash: {
      image: `./assets/images/${brand}-splash.png`,
      backgroundColor: '<colour>',
    },
    updates: {
      fallbackToCacheTimeout: 0,
    },
    assetBundlePatterns: ['**/*'],
    ios: {
      backgroundColor: '#000000',
      buildNumber: `${BUILD_NUMBER}`,
      bundleIdentifier: appIdentifier,
      config: { usesNonExemptEncryption: false },
    },
    android: {
      package: appIdentifier,
      versionCode: BUILD_NUMBER,
      adaptiveIcon: {
        foregroundImage: `./assets/images/adaptive-icon-${appEnv}.png`,
        backgroundColor: { development: '<colour>', production: '<colour>' }[
          appEnv
        ],
      },
      blockedPermissions: [
        // expo-av requires android record audio by default but we dont need it as of yet
        'android.permission.RECORD_AUDIO',
      ],
      googleServicesFile: './google-services.json',
    },
    web: {
      favicon: `./assets/images/${brand}-${appEnv}-favicon.png`,
    },
    extra: {
      ...config[brand][appEnv],
      eas: {
        projectId: '<project-id>',
      },
    },
    plugins: [
      [
        'expo-datadog',
        {
          errorTracking: {
            // https://docs.datadoghq.com/real_user_monitoring/error_tracking/expo/#plugin-configuration-options
            iosDsyms: !isLocalBuild,
            iosSourcemaps: !isLocalBuild,
            androidProguardMappingFiles: !isLocalBuild,
            androidSourcemaps: !isLocalBuild,
          },
        },
      ],
      [
        'expo-community-flipper',
        {
          version: '0.175.0',
          ios: { enabled: isLocalBuild },
          android: { enabled: isLocalBuild },
        },
      ],
      [
        'customerio-expo-plugin',
        {
          android: {
            googleServicesFile: './google-services.json',
          },
          ios: {
            pushNotification: {
              // This being true currently breaks the iOS builds as per
              // https://github.com/eucalyptusvc/mobile/pull/171#issuecomment-1427140902
              useRichPush: false,
              env: {
                siteId: config[brand][appEnv].customerIO.siteId,
                apiKey: config[brand][appEnv].customerIO.apiKey,
                region: config[brand][appEnv].customerIO.region,
              },
            },
          },
        },
      ],
      [
        'expo-build-properties',
        {
          // Version 33 is needed to support expo-notifications requesting
          // notification permissions:
          // https://github.com/expo/expo/issues/19735#issuecomment-1385842618
          android: {
            compileSdkVersion: 33,
            targetSdkVersion: 33,
            buildToolsVersion: '31.0.0',
          },
          ios: {
            // Version 13.0 is required to support Customer.io:
            // https://customer.io/docs/sdk/expo/getting-started/#ios-specific-instructions
            deploymentTarget: '13.0',
          },
        },
      ],
      '<internal-module>',
    ],
    jsEngine: 'hermes',
  };
};
xtreem88 commented 1 year ago

Hi @euc-callum, Thanks for reaching out and providing more information to resolve this issue.

One thing I am confused about is how you have <identifier>.richpush; the bundle identifier for NotificationService is defined here.

Our plugin creates the NotificationService target in your Xcode project and appends .richpush to the main bundle identifier. This would require creating a provisioning profile for <your.main.identifier>.richpush.

Alternatively, you can enable automatic signing by passing the "-allowProvisioningUpdates" flag to the xcodebuild command, which will allow Xcode to generate a new provisioning profile for you automatically. See more here.

euc-callum commented 1 year ago

Ah, apologies if it wasn't clear but its the same:

bundleIdentifier: appIdentifier,

where appIdentifier is equivalent to identifier, apologies for the inconsistency in how I wrote those two early message.

euc-callum commented 1 year ago

I can't see a mechanism for enabling automatic signing in Expo's eas build command.

Given this appears to be an undocumented requirement to utilise richPush on iOS with this plugin in Expo, would it be possible to explain / document this with an Expo-compatible approach?

One thing to note - I attempted to reproduce the error I was originally receiving last week, but I'm now instead receiving an alternative set of errors, likely before I reach the initial error reported above.

Compiling customerio-reactnative Pods/CustomerIOCommon » UIKitWrapper.swift

❌  (ios/Pods/CustomerIOCommon/Sources/Common/Util/UIKitWrapper.swift:19:23)

  17 |     public func open(url: URL) {
  18 |         #if canImport(UIKit)
> 19 |         UIApplication.shared.open(url: url)
     |                       ^ 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.
  20 |         #endif
  21 |     }
  22 | 

❌  (ios/Pods/CustomerIOCommon/Sources/Common/Util/UIKitWrapper.swift:19:30)

  17 |     public func open(url: URL) {
  18 |         #if canImport(UIKit)
> 19 |         UIApplication.shared.open(url: url)
     |                              ^ 'open' is unavailable in application extensions for iOS
  20 |         #endif
  21 |     }
  22 | 

❌  (ios/Pods/CustomerIOCommon/Sources/Common/Util/UIKitWrapper.swift:32:50)

  30 |         openLinkInHostAppActivity.webpageURL = webpageURL
  31 | 
> 32 |         let didHostAppHandleLink = UIApplication.shared.delegate?.application?(UIApplication.shared, continue: openLinkInHostAppActivity, restorationHandler: { _ in }) ?? false
     |                                                  ^ 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.
  33 | 
  34 |         return didHostAppHandleLink
  35 |         #else

❌  (ios/Pods/CustomerIOCommon/Sources/Common/Util/UIKitWrapper.swift:32:94)

  30 |         openLinkInHostAppActivity.webpageURL = webpageURL
  31 | 
> 32 |         let didHostAppHandleLink = UIApplication.shared.delegate?.application?(UIApplication.shared, continue: openLinkInHostAppActivity, restorationHandler: { _ in }) ?? false
     |                                                                                              ^ 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.
  33 | 
  34 |         return didHostAppHandleLink
  35 |         #else

At a guess this could be an issue with customerio-ios's new release three days after I raised this issue? The podfile.lock in our project specifies we're using 2.0.6 now for CustomerIOCommon.

xtreem88 commented 1 year ago

At a guess this could be an issue with customerio-ios's new release three days after I raised this issue? The podfile.lock in our project specifies we're using 2.0.6 now for CustomerIOCommon.

Yes, you are correct; we are aware of this issue and we are working on a fix for this issue, the fix would be out soon. But to unblock you after running prebuild, apply this workaround and then run pod install

Given this appears to be an undocumented requirement to utilise richPush on iOS with this plugin in Expo, would it be possible to explain / document this with an Expo-compatible approach?

I apologize for any confusion regarding our mobile SDKs. We are currently working on updating our documentation, and one of the changes we are making is related to code signing.

Please follow this link to access Expo’s documentation on automatically managed credentials: https://docs.expo.dev/app-signing/managed-credentials/

euc-callum commented 1 year ago

Hi @xtreem88, I'm attempting to progress further on this, but now seeing a failed build with:

2023-02-23 18:55:36.086 xcodebuild[9249:23361] warning: The file reference for "NotificationService" is a member of multiple groups ("Pods" and ""); this indicates a malformed project. Only the membership in one of the groups will be preserved (but membership in targets will be unaffected). If you want a reference to the same file in more than one group, please add another reference to the same path.

When I attempt to run a build in Expo.dev. As far as I can tell this NotificationService is something resulting from Customer.IO?

xtreem88 commented 1 year ago

Hi @euc-callum please confirm that you are on version 1.0.0-beta.3

MatiasLjubica commented 1 year ago

@xtreem88 Hi, I'm facing a similar issue for IOS with the last package, i activate notification, I start to prebuild the project, I use the eas credentials -p ios to generate new provisioning profile for xxx.rishpush, I see clearly the configuration, but each time i build, i got this error on the Fastline process.

❌ error: No profiles for 'com.xxx.mobile.richpush' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.xxx.mobile.richpush'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'NotificationService' from project 'Yomoni')

xtreem88 commented 1 year ago

Hi @MatiasLjubica I'm sorry about the issue you are facing Can you post the exact bundle IDs you used? From the error you posted, it looks like com.xxx.mobile.richpush is required, and what you used is xxx.rishpush also, there seems to be a typo; it should be richpush not rishpush

MatiasLjubica commented 1 year ago

I can't write the full app name of my company but i never change the extension name so far, all was auto-created from the Customer Expo Plugin and the "eas credentials -p" command

xtreem88 commented 1 year ago

Can you confirm that the bundle ID you provisioned matches the one generated? please check for typos.

MatiasLjubica commented 1 year ago

@xtreem88 sorry when i posted the message i was made a typo on com.xxx.mobile.rishpush but is the bundle ID is com.xxx.mobile.richpush, you can see on the error message

ami-aman commented 1 year ago

Hi @MatiasLjubica Stepping in for Segun. I am sorry that you are having issues building the app. Let me give a brief about the possible issue.

Our plugin creates NotificationService Extension for you with a bundle identifier based on the bundle identifier for your main target. For example, if the bundle identifier of your main target is com.yourcompany.app then our plugin creates NotificationService Extension with com.companyname.app.richpush as the bundle Id. Now that you do not have Automatically manage signing checked hence Xcode does not create new provisioning profile matching the bundle identifier that our plugin created and that's what the error is about. It is completely okay to not check Automatically manage signing.

Looking at the errors, as it seems like your provisioning profiles are not compatible with this bundle Id. I would suggest you to do prebuild --clean and then before you start building your project, make sure to update the bundle Id as required. Refer the screenshot below :

Screenshot 2023-03-31 at 6 44 14 PM

Do let us know if this solves your issue.