achorein / expo-share-intent

🚀 Simple share intent in an Expo Native Module
MIT License
221 stars 16 forks source link

Allow custom application group identifier #94

Open m1st1ck opened 3 months ago

m1st1ck commented 3 months ago

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 commented 2 months ago

Need more flexibility with app identifier (https://github.com/achorein/expo-share-intent/issues/88) and group identifier.

achorein commented 1 month ago

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

m1st1ck commented 1 month ago

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

What I did

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 commented 1 month ago

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