diff --git a/ios/App/App/SharedImageUtility.swift b/ios/App/App/SharedImageUtility.swift index 10d46ba2..42be0aeb 100644 --- a/ios/App/App/SharedImageUtility.swift +++ b/ios/App/App/SharedImageUtility.swift @@ -20,7 +20,24 @@ public class SharedImageUtility { private static var appGroupContainerURL: URL? { return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) } - + + private static func logShareDiagnostic(method: String, userDefaults: UserDefaults?) { + let shareId = userDefaults?.string(forKey: sharedPhotoShareIdKey) + let filePath = userDefaults?.string(forKey: sharedPhotoFilePathKey) + let metadataExists = filePath != nil + let fileExists: Bool + if let filePath = filePath, let containerURL = appGroupContainerURL { + let fileURL = containerURL.appendingPathComponent(filePath) + fileExists = FileManager.default.fileExists(atPath: fileURL.path) + } else { + fileExists = false + } + + let shareIdLog = shareId ?? "nil" + let filePathLog = filePath ?? "nil" + print("[ShareTarget] \(method) shareId=\(shareIdLog) sharedPhotoFilePath=\(filePathLog) metadataExists=\(metadataExists) fileExists=\(fileExists)") + } + /** * Get shared image data from App Group container file * All images are stored as files for consistency and to avoid UserDefaults size limits @@ -29,7 +46,10 @@ public class SharedImageUtility { * @returns Dictionary with "base64" and "fileName" keys, or nil if no shared image */ static func getSharedImageData() -> [String: String]? { - guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier) else { + let userDefaults = UserDefaults(suiteName: appGroupIdentifier) + logShareDiagnostic(method: "getSharedImageData", userDefaults: userDefaults) + + guard let userDefaults = userDefaults else { return nil } @@ -64,7 +84,10 @@ public class SharedImageUtility { * @returns true if shared image file exists, false otherwise */ static func hasSharedImage() -> Bool { - guard let userDefaults = UserDefaults(suiteName: appGroupIdentifier), + let userDefaults = UserDefaults(suiteName: appGroupIdentifier) + logShareDiagnostic(method: "hasSharedImage", userDefaults: userDefaults) + + guard let userDefaults = userDefaults, let filePath = userDefaults.string(forKey: sharedPhotoFilePathKey), let containerURL = appGroupContainerURL else { return false