Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom application group identifier #94

Closed
m1st1ck opened this issue Aug 12, 2024 · 5 comments · Fixed by #117
Closed

Allow custom application group identifier #94

m1st1ck opened this issue Aug 12, 2024 · 5 comments · Fixed by #117
Labels
enhancement New feature or request ios

Comments

@m1st1ck
Copy link

m1st1ck commented Aug 12, 2024

When trying to submit a build with eas we get the following error

There is a problem with the request entity - An Application Group with Identifier 'group.com.xx.xxx' is not available. Please enter a different string.

Remove the value 'group.com.xx.xxx' from the array 'com.apple.security.application-groups' in the iOS project entitlements.
If you know that the ID is registered to one of your apps, try again with a different Apple account.

Our solution right now it patch the package and replace the identifier with custom one, but it would be nice if it can be changed with config option.

Here is the patch if it is any help

diff --git a/node_modules/expo-share-intent/ios/ExpoShareIntentModule.swift b/node_modules/expo-share-intent/ios/ExpoShareIntentModule.swift
index 23f28d2..e0ffe20 100644
--- a/node_modules/expo-share-intent/ios/ExpoShareIntentModule.swift
+++ b/node_modules/expo-share-intent/ios/ExpoShareIntentModule.swift
@@ -33,7 +33,7 @@ public class ExpoShareIntentModule: Module {
     }
 
     Function("clearShareIntent") { (sharedKey: String) in
-        let userDefaults = UserDefaults(suiteName: "group.\(Bundle.main.bundleIdentifier!)")
+        let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
         userDefaults?.set(nil, forKey: sharedKey)
         userDefaults?.synchronize()
     }
@@ -51,7 +51,7 @@ public class ExpoShareIntentModule: Module {
   private var latestText: String? = nil
 
   private func handleUrl(url: URL?) -> String? {
-    let appDomain = Bundle.main.bundleIdentifier!
+    let appDomain = "com.xx.xxx"
     if let url = url {
         let userDefaults = UserDefaults(suiteName: "group.\(appDomain)")
         if url.fragment == "media" {
diff --git a/node_modules/expo-share-intent/plugin/build/ios/ShareExtensionViewController.swift b/node_modules/expo-share-intent/plugin/build/ios/ShareExtensionViewController.swift
index 6703686..8c72f1f 100644
--- a/node_modules/expo-share-intent/plugin/build/ios/ShareExtensionViewController.swift
+++ b/node_modules/expo-share-intent/plugin/build/ios/ShareExtensionViewController.swift
@@ -58,7 +58,7 @@ class ShareViewController: SLComposeServiceViewController {
           
         // If this is the last item, save sharedText in userDefaults and redirect to host app
         if index == (content.attachments?.count)! - 1 {
-          let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
+          let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
           userDefaults?.set(this.sharedText, forKey: this.sharedKey)
           userDefaults?.synchronize()
           this.redirectToHostApp(type: .text)
@@ -78,7 +78,7 @@ class ShareViewController: SLComposeServiceViewController {
         
         // If this is the last item, save sharedText in userDefaults and redirect to host app
         if index == (content.attachments?.count)! - 1 {
-          let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
+          let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
           userDefaults?.set(this.sharedText, forKey: this.sharedKey)
           userDefaults?.synchronize()
           this.redirectToHostApp(type: .weburl)
@@ -114,7 +114,7 @@ class ShareViewController: SLComposeServiceViewController {
         let mimeType = url!.mimeType(ext: fileExtension)
         let newName = "\(UUID().uuidString).\(fileExtension)"
         let newPath = FileManager.default
-          .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
+          .containerURL(forSecurityApplicationGroupIdentifier: "group.com.xx.xxx")!
           .appendingPathComponent(newName)
         let copied = this.copyFile(at: url!, to: newPath)
         if(copied) {
@@ -123,7 +123,7 @@ class ShareViewController: SLComposeServiceViewController {
   
         // If this is the last item, save imagesData in userDefaults and redirect to host app
         if index == (content.attachments?.count)! - 1 {
-          let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
+          let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
           userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
           userDefaults?.synchronize()
           this.redirectToHostApp(type: .media)
@@ -161,7 +161,7 @@ class ShareViewController: SLComposeServiceViewController {
         let mimeType = url.mimeType(ext: fileExtension)
         let newName = "\(UUID().uuidString).\(fileExtension)"
         let newPath = FileManager.default
-          .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
+          .containerURL(forSecurityApplicationGroupIdentifier: "group.com.xx.xxx")!
           .appendingPathComponent(newName)
         let copied = this.copyFile(at: url, to: newPath)
         if(copied) {
@@ -173,7 +173,7 @@ class ShareViewController: SLComposeServiceViewController {
   
         // If this is the last item, save imagesData in userDefaults and redirect to host app
         if index == (content.attachments?.count)! - 1 {
-          let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
+          let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
           userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
           userDefaults?.synchronize()
           this.redirectToHostApp(type: .media)
@@ -196,7 +196,7 @@ class ShareViewController: SLComposeServiceViewController {
         let mimeType = url.mimeType(ext: fileExtension)
         let newName = "\(UUID().uuidString).\(fileExtension)"
         let newPath = FileManager.default
-          .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
+          .containerURL(forSecurityApplicationGroupIdentifier: "group.com.xx.xxx")!
           .appendingPathComponent(newName)
         let copied = this.copyFile(at: url, to: newPath)
         if (copied) {
@@ -204,7 +204,7 @@ class ShareViewController: SLComposeServiceViewController {
         }
         
         if index == (content.attachments?.count)! - 1 {
-          let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
+          let userDefaults = UserDefaults(suiteName: "group.com.xx.xxx")
           userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
           userDefaults?.synchronize()
           this.redirectToHostApp(type: .file)
@@ -336,7 +336,7 @@ class ShareViewController: SLComposeServiceViewController {
   private func getThumbnailPath(for url: URL) -> URL {
     let fileName = Data(url.lastPathComponent.utf8).base64EncodedString().replacingOccurrences(of: "==", with: "")
     let path = FileManager.default
-      .containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
+      .containerURL(forSecurityApplicationGroupIdentifier: "group.com.xx.xxx")!
       .appendingPathComponent("\(fileName).jpg")
     return path
   }
diff --git a/node_modules/expo-share-intent/plugin/build/ios/constants.js b/node_modules/expo-share-intent/plugin/build/ios/constants.js
index d94b3ab..ff7e123 100644
--- a/node_modules/expo-share-intent/plugin/build/ios/constants.js
+++ b/node_modules/expo-share-intent/plugin/build/ios/constants.js
@@ -6,7 +6,7 @@ exports.shareExtensionInfoFileName = `${exports.shareExtensionName}-Info.plist`;
 exports.shareExtensionEntitlementsFileName = `${exports.shareExtensionName}.entitlements`;
 exports.shareExtensionStoryBoardFileName = "MainInterface.storyboard";
 exports.shareExtensionViewControllerFileName = "ShareViewController.swift";
-const getAppGroups = (identifier) => [`group.${identifier}`];
+const getAppGroups = (identifier) => [`group.com.xx.xxx`];
 exports.getAppGroups = getAppGroups;
 const getShareExtensionBundledIdentifier = (appIdentifier) => `${appIdentifier}.share-extension`;
 exports.getShareExtensionBundledIdentifier = getShareExtensionBundledIdentifier;

@achorein achorein added bug Something isn't working ios labels Sep 13, 2024
@achorein
Copy link
Owner

achorein commented Sep 13, 2024

Need more flexibility with app identifier (#88) and group identifier.

@achorein achorein added enhancement New feature or request and removed bug Something isn't working labels Sep 13, 2024
@achorein
Copy link
Owner

@m1st1ck do you have a way of testing this PR to make sure it fixes your problem?

@m1st1ck
Copy link
Author

m1st1ck commented Oct 17, 2024

@achorein I tried to test but probably not doing it correctly

What I did

  • yarn add achorein/expo-share-intent#feat/custom-ios-identifiers
  • cd ./node_modules/expo-share-intent && yarn && yarn prepare
  • update app config to include iosAppGroupIdentifier
  • eas build -p ios --local

without the patch, the build fails on main branch and is successful on this one, and I can see the app when sharing.

However, I might be missing something because when I open the app it is stuck on the splash screen.
I tried with expo prebuild --clean && npx expo run:ios, then it just shows black screen after the splash, unless I comment out useShareIntent.
The issue is on both main and this branch, so that's why I think I am missing something, maybe some build step.

Let me know if I should try it differently.

@achorein
Copy link
Owner

🤔 looks good, yarn prepare and expo prebuild --clean are enough

@achorein
Copy link
Owner

achorein commented Dec 9, 2024

@m1st1ck now available in v2.6.0 and v3.1.0 with iosAppGroupIdentifier parameters 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ios
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants