From 7fc60e939e67b7f0c1f3077376aaa1060dd8ee5e Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Thu, 5 Jun 2025 00:06:17 -0400 Subject: [PATCH] Fixed App Groups --- GIF Collector.xcodeproj/project.pbxproj | 2 ++ GIFCollector/GIF.swift | 2 ++ GIFCollector/GIFCollector.entitlements | 2 +- GIFCollector/Services/GIFFileManager.swift | 9 ++++----- GIFCollector/Services/GIFStorageService.swift | 5 ++--- GIFCollectorIM/GIFCollectorIM.entitlements | 2 +- GIFCollectorShare/GIFCollectorShare.entitlements | 2 +- GIFCollectorShare/ShareViewController.swift | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/GIF Collector.xcodeproj/project.pbxproj b/GIF Collector.xcodeproj/project.pbxproj index 0c33d95..41bc20d 100644 --- a/GIF Collector.xcodeproj/project.pbxproj +++ b/GIF Collector.xcodeproj/project.pbxproj @@ -589,6 +589,7 @@ buildSettings = { CODE_SIGN_ENTITLEMENTS = GIFCollectorShare/GIFCollectorShare.entitlements; CODE_SIGN_IDENTITY = ""; + CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = ""; @@ -617,6 +618,7 @@ buildSettings = { CODE_SIGN_ENTITLEMENTS = GIFCollectorShare/GIFCollectorShare.entitlements; CODE_SIGN_IDENTITY = ""; + CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = ""; diff --git a/GIFCollector/GIF.swift b/GIFCollector/GIF.swift index 451bda4..cc9f11f 100644 --- a/GIFCollector/GIF.swift +++ b/GIFCollector/GIF.swift @@ -1,5 +1,7 @@ import Foundation + + // Removed SwiftData dependency to ensure compatibility across targets struct GIF: Codable, Identifiable, Equatable { let id: UUID diff --git a/GIFCollector/GIFCollector.entitlements b/GIFCollector/GIFCollector.entitlements index 55d92e4..b80d31e 100644 --- a/GIFCollector/GIFCollector.entitlements +++ b/GIFCollector/GIFCollector.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.gifcollector + group.com.abunchofknowitalls.GIFCollector diff --git a/GIFCollector/Services/GIFFileManager.swift b/GIFCollector/Services/GIFFileManager.swift index 2165156..56eac89 100644 --- a/GIFCollector/Services/GIFFileManager.swift +++ b/GIFCollector/Services/GIFFileManager.swift @@ -1,6 +1,8 @@ import Foundation import UIKit +var appGroupID = "group."+Bundle.main.bundleIdentifier.unsafelyUnwrapped + class GIFFileManager { static let shared = GIFFileManager() @@ -12,9 +14,6 @@ class GIFFileManager { // Always use the App Group container for consistent storage between extensions private var documentsDirectory: URL { - // Use a constant app group ID to ensure consistency across targets - let appGroupID = "group.gifcollector" - if let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID) { return containerURL } else { @@ -162,7 +161,7 @@ class GIFFileManager { let fileURLs = try FileManager.default.contentsOfDirectory(at: gifsDirectory, includingPropertiesForKeys: nil) // Find any shared GIF that matches our URL (usually won't find any, but helps avoid duplicates) - let userDefaults = UserDefaults(suiteName: "group.gifcollector") + let userDefaults = UserDefaults(suiteName: appGroupID) if let pendingGIFs = userDefaults?.array(forKey: "pendingGIFs") as? [[String: Any]] { for gifInfo in pendingGIFs { if let originURL = gifInfo["originalURL"] as? String, @@ -179,4 +178,4 @@ class GIFFileManager { return nil } } -} \ No newline at end of file +} diff --git a/GIFCollector/Services/GIFStorageService.swift b/GIFCollector/Services/GIFStorageService.swift index 5bac2f6..de4a6ee 100644 --- a/GIFCollector/Services/GIFStorageService.swift +++ b/GIFCollector/Services/GIFStorageService.swift @@ -4,8 +4,7 @@ class GIFStorageService { static let shared = GIFStorageService() // Use constant App Group ID to ensure consistency across targets - private let appGroupID = "group.gifcollector" - private let userDefaults = UserDefaults(suiteName: "group.gifcollector") + private let userDefaults = UserDefaults(suiteName: appGroupID) // Use a consistent key for saved GIFs across all extensions private let savedGIFsKey = "sharedGIFs" @@ -217,4 +216,4 @@ class GIFStorageService { userDefaults?.synchronize() print("Cleared pending GIFs from shared storage") } -} \ No newline at end of file +} diff --git a/GIFCollectorIM/GIFCollectorIM.entitlements b/GIFCollectorIM/GIFCollectorIM.entitlements index 55d92e4..b80d31e 100644 --- a/GIFCollectorIM/GIFCollectorIM.entitlements +++ b/GIFCollectorIM/GIFCollectorIM.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.gifcollector + group.com.abunchofknowitalls.GIFCollector diff --git a/GIFCollectorShare/GIFCollectorShare.entitlements b/GIFCollectorShare/GIFCollectorShare.entitlements index 55d92e4..b80d31e 100644 --- a/GIFCollectorShare/GIFCollectorShare.entitlements +++ b/GIFCollectorShare/GIFCollectorShare.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.gifcollector + group.com.abunchofknowitalls.GIFCollector diff --git a/GIFCollectorShare/ShareViewController.swift b/GIFCollectorShare/ShareViewController.swift index 053aa88..2020e89 100644 --- a/GIFCollectorShare/ShareViewController.swift +++ b/GIFCollectorShare/ShareViewController.swift @@ -17,7 +17,7 @@ class ShareViewController: SLComposeServiceViewController { private var debugMessages: [String] = [] // Use the same constants as in the main app - private let appGroupID = "group.gifcollector" + private let appGroupID = "group."+Bundle.main.bundleIdentifier.unsafelyUnwrapped private let pendingGIFsKey = "pendingGIFs" override func viewDidLoad() {