10 Commits

Author SHA1 Message Date
Joshua Higgins
a07814064d Fix border and add icon inconsistency 2025-06-26 23:34:10 -04:00
Joshua Higgins
073c0fa351 Compilation targets, iOS 26 2025-06-12 18:06:32 -04:00
Joshua Higgins
8b572b8918 More fixes to groups 2025-06-05 00:22:56 -04:00
Joshua Higgins
7fc60e939e Fixed App Groups 2025-06-05 00:06:17 -04:00
Joshua Higgins
15525c9abe Finished ShareSheet, Basic App, and restructure 2025-06-04 23:02:24 -04:00
Joshua Higgins
718436764d Remade project structure 2025-06-04 13:57:32 -04:00
Joshua Higgins
b27b223a5e Trying to make share extension, have to recreate project 2025-06-04 13:54:13 -04:00
Joshua Higgins
36949981b4 Ability to Delete GIFs 2025-06-03 22:37:09 -04:00
Joshua Higgins
8ce5adc766 Save GIFs Locally 2025-06-03 22:18:23 -04:00
Joshua Higgins
a09e08763f Clean up 2025-06-02 20:17:55 -04:00
57 changed files with 2445 additions and 764 deletions

View File

@@ -0,0 +1,693 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 77;
objects = {
/* Begin PBXBuildFile section */
1B29521A2DF0B6A1002148EF /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B2952192DF0B6A1002148EF /* Messages.framework */; };
1B2952262DF0B6A3002148EF /* GIFCollectorIM.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 1B2952172DF0B6A1002148EF /* GIFCollectorIM.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1B29523A2DF0B734002148EF /* GIFCollectorShare.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 1B2952302DF0B734002148EF /* GIFCollectorShare.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
1B2952242DF0B6A3002148EF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1B2951FB2DF0B611002148EF /* Project object */;
proxyType = 1;
remoteGlobalIDString = 1B2952162DF0B6A1002148EF;
remoteInfo = "GIF Collector";
};
1B2952382DF0B734002148EF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1B2951FB2DF0B611002148EF /* Project object */;
proxyType = 1;
remoteGlobalIDString = 1B29522F2DF0B734002148EF;
remoteInfo = share;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
1B29522B2DF0B6A3002148EF /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
1B29523A2DF0B734002148EF /* GIFCollectorShare.appex in Embed Foundation Extensions */,
1B2952262DF0B6A3002148EF /* GIFCollectorIM.appex in Embed Foundation Extensions */,
);
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1B2952032DF0B611002148EF /* GIFCollector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GIFCollector.app; sourceTree = BUILT_PRODUCTS_DIR; };
1B2952172DF0B6A1002148EF /* GIFCollectorIM.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = GIFCollectorIM.appex; sourceTree = BUILT_PRODUCTS_DIR; };
1B2952192DF0B6A1002148EF /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = System/Library/Frameworks/Messages.framework; sourceTree = SDKROOT; };
1B2952302DF0B734002148EF /* GIFCollectorShare.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = GIFCollectorShare.appex; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
1B2952272DF0B6A3002148EF /* Exceptions for "GIFCollectorIM" folder in "GIFCollectorIM" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 1B2952162DF0B6A1002148EF /* GIFCollectorIM */;
};
1B29523B2DF0B734002148EF /* Exceptions for "GIFCollectorShare" folder in "GIFCollectorShare" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 1B29522F2DF0B734002148EF /* GIFCollectorShare */;
};
1B4125C72DF0D5FB001B8215 /* Exceptions for "GIFCollector" folder in "GIFCollectorIM" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
ContentView.swift,
GIF.swift,
GIFCollectionViewCell.swift,
Services/DownloadService.swift,
Services/GIFFileManager.swift,
Services/GIFStorageService.swift,
Views/AddGIFViewController.swift,
Views/GIFCollectionViewController.swift,
Views/GIFPlayerView.swift,
);
target = 1B2952162DF0B6A1002148EF /* GIFCollectorIM */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
1B2952052DF0B611002148EF /* GIFCollector */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
1B4125C72DF0D5FB001B8215 /* Exceptions for "GIFCollector" folder in "GIFCollectorIM" target */,
);
path = GIFCollector;
sourceTree = "<group>";
};
1B29521B2DF0B6A2002148EF /* GIFCollectorIM */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
1B2952272DF0B6A3002148EF /* Exceptions for "GIFCollectorIM" folder in "GIFCollectorIM" target */,
);
path = GIFCollectorIM;
sourceTree = "<group>";
};
1B2952312DF0B734002148EF /* GIFCollectorShare */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
1B29523B2DF0B734002148EF /* Exceptions for "GIFCollectorShare" folder in "GIFCollectorShare" target */,
);
path = GIFCollectorShare;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
1B2952002DF0B611002148EF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B2952142DF0B6A1002148EF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1B29521A2DF0B6A1002148EF /* Messages.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1B29522D2DF0B734002148EF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
1B2951FA2DF0B611002148EF = {
isa = PBXGroup;
children = (
1B2952052DF0B611002148EF /* GIFCollector */,
1B29521B2DF0B6A2002148EF /* GIFCollectorIM */,
1B2952312DF0B734002148EF /* GIFCollectorShare */,
1B2952182DF0B6A1002148EF /* Frameworks */,
1B2952042DF0B611002148EF /* Products */,
);
sourceTree = "<group>";
};
1B2952042DF0B611002148EF /* Products */ = {
isa = PBXGroup;
children = (
1B2952032DF0B611002148EF /* GIFCollector.app */,
1B2952172DF0B6A1002148EF /* GIFCollectorIM.appex */,
1B2952302DF0B734002148EF /* GIFCollectorShare.appex */,
);
name = Products;
sourceTree = "<group>";
};
1B2952182DF0B6A1002148EF /* Frameworks */ = {
isa = PBXGroup;
children = (
1B2952192DF0B6A1002148EF /* Messages.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
1B2952022DF0B611002148EF /* GIFCollector */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1B2952102DF0B613002148EF /* Build configuration list for PBXNativeTarget "GIFCollector" */;
buildPhases = (
1B2951FF2DF0B611002148EF /* Sources */,
1B2952002DF0B611002148EF /* Frameworks */,
1B2952012DF0B611002148EF /* Resources */,
1B29522B2DF0B6A3002148EF /* Embed Foundation Extensions */,
);
buildRules = (
);
dependencies = (
1B2952252DF0B6A3002148EF /* PBXTargetDependency */,
1B2952392DF0B734002148EF /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
1B2952052DF0B611002148EF /* GIFCollector */,
);
name = GIFCollector;
packageProductDependencies = (
);
productName = gif;
productReference = 1B2952032DF0B611002148EF /* GIFCollector.app */;
productType = "com.apple.product-type.application";
};
1B2952162DF0B6A1002148EF /* GIFCollectorIM */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1B2952282DF0B6A3002148EF /* Build configuration list for PBXNativeTarget "GIFCollectorIM" */;
buildPhases = (
1B2952132DF0B6A1002148EF /* Sources */,
1B2952142DF0B6A1002148EF /* Frameworks */,
1B2952152DF0B6A1002148EF /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
1B29521B2DF0B6A2002148EF /* GIFCollectorIM */,
);
name = GIFCollectorIM;
packageProductDependencies = (
);
productName = "GIF Collector";
productReference = 1B2952172DF0B6A1002148EF /* GIFCollectorIM.appex */;
productType = "com.apple.product-type.app-extension.messages";
};
1B29522F2DF0B734002148EF /* GIFCollectorShare */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1B29523C2DF0B734002148EF /* Build configuration list for PBXNativeTarget "GIFCollectorShare" */;
buildPhases = (
1B29522C2DF0B734002148EF /* Sources */,
1B29522D2DF0B734002148EF /* Frameworks */,
1B29522E2DF0B734002148EF /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
1B2952312DF0B734002148EF /* GIFCollectorShare */,
);
name = GIFCollectorShare;
packageProductDependencies = (
);
productName = share;
productReference = 1B2952302DF0B734002148EF /* GIFCollectorShare.appex */;
productType = "com.apple.product-type.app-extension";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
1B2951FB2DF0B611002148EF /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1640;
LastUpgradeCheck = 1640;
TargetAttributes = {
1B2952022DF0B611002148EF = {
CreatedOnToolsVersion = 16.4;
};
1B2952162DF0B6A1002148EF = {
CreatedOnToolsVersion = 16.4;
};
1B29522F2DF0B734002148EF = {
CreatedOnToolsVersion = 16.4;
};
};
};
buildConfigurationList = 1B2951FE2DF0B611002148EF /* Build configuration list for PBXProject "GIF Collector" */;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 1B2951FA2DF0B611002148EF;
minimizedProjectReferenceProxies = 1;
preferredProjectObjectVersion = 77;
productRefGroup = 1B2952042DF0B611002148EF /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
1B2952022DF0B611002148EF /* GIFCollector */,
1B2952162DF0B6A1002148EF /* GIFCollectorIM */,
1B29522F2DF0B734002148EF /* GIFCollectorShare */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
1B2952012DF0B611002148EF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B2952152DF0B6A1002148EF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B29522E2DF0B734002148EF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
1B2951FF2DF0B611002148EF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B2952132DF0B6A1002148EF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B29522C2DF0B734002148EF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
1B2952252DF0B6A3002148EF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 1B2952162DF0B6A1002148EF /* GIFCollectorIM */;
targetProxy = 1B2952242DF0B6A3002148EF /* PBXContainerItemProxy */;
};
1B2952392DF0B734002148EF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 1B29522F2DF0B734002148EF /* GIFCollectorShare */;
targetProxy = 1B2952382DF0B734002148EF /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
1B29520E2DF0B613002148EF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
1B29520F2DF0B613002148EF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
1B2952112DF0B613002148EF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = GIFCollector/GIFCollector.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
1B2952122DF0B613002148EF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = GIFCollector/GIFCollector.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
1B2952292DF0B6A3002148EF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_ENTITLEMENTS = GIFCollectorIM/GIFCollectorIM.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GIFCollectorIM/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.iMessage;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
1B29522A2DF0B6A3002148EF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_ENTITLEMENTS = GIFCollectorIM/GIFCollectorIM.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GIFCollectorIM/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.iMessage;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
1B29523D2DF0B734002148EF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = GIFCollectorShare/GIFCollectorShare.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GIFCollectorShare/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.Share;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
1B29523E2DF0B734002148EF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = GIFCollectorShare/GIFCollectorShare.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8S7C654DQ4;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = GIFCollectorShare/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 100.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.Share;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1B2951FE2DF0B611002148EF /* Build configuration list for PBXProject "GIF Collector" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B29520E2DF0B613002148EF /* Debug */,
1B29520F2DF0B613002148EF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1B2952102DF0B613002148EF /* Build configuration list for PBXNativeTarget "GIFCollector" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B2952112DF0B613002148EF /* Debug */,
1B2952122DF0B613002148EF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1B2952282DF0B6A3002148EF /* Build configuration list for PBXNativeTarget "GIFCollectorIM" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B2952292DF0B6A3002148EF /* Debug */,
1B29522A2DF0B6A3002148EF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1B29523C2DF0B734002148EF /* Build configuration list for PBXNativeTarget "GIFCollectorShare" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B29523D2DF0B734002148EF /* Debug */,
1B29523E2DF0B734002148EF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 1B2951FB2DF0B611002148EF /* Project object */;
}

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1640"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952162DF0B6A1002148EF"
BuildableName = "GIFCollectorIM.appex"
BlueprintName = "GIFCollectorIM"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
askForAppToLaunch = "Yes"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1640"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1640"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B29522F2DF0B734002148EF"
BuildableName = "GIFCollectorShare.appex"
BlueprintName = "GIFCollectorShare"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
askForAppToLaunch = "Yes"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1B2952022DF0B611002148EF"
BuildableName = "GIFCollector.app"
BlueprintName = "GIFCollector"
ReferencedContainer = "container:GIF Collector.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -1,143 +0,0 @@
//
// MessagesViewController.swift
// GIFCollector MessagesExtension
//
// Created by Joshua Higgins on 6/2/25.
//
import UIKit
import Messages
class MessagesViewController: MSMessagesAppViewController {
private var gifCollectionVC: GIFCollectionViewController?
override func viewDidLoad() {
super.viewDidLoad()
setupChildViewController()
}
private func setupChildViewController() {
let collectionVC = GIFCollectionViewController()
collectionVC.onSelectGIF = { [weak self] gif in
self?.sendGIF(gif)
}
addChild(collectionVC)
collectionVC.view.frame = view.bounds
collectionVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(collectionVC.view)
collectionVC.didMove(toParent: self)
gifCollectionVC = collectionVC
}
private func sendGIF(_ gif: GIF) {
guard let conversation = activeConversation,
let gifURL = gif.url else { return }
// Show a loading indicator
let loadingAlert = UIAlertController(title: "Preparing GIF", message: "Please wait...", preferredStyle: .alert)
present(loadingAlert, animated: true)
// Download the GIF data
GIFDownloadService.shared.downloadGIF(from: gif.urlString) { data, error in
DispatchQueue.main.async {
// Dismiss the loading indicator
self.dismiss(animated: true) {
if let error = error {
self.showErrorAlert(error: error)
return
}
guard let gifData = data else {
self.showErrorAlert(message: "Failed to download GIF")
return
}
// Create a temporary file URL for the GIF
let tempDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let tempFileURL = tempDirectoryURL.appendingPathComponent(UUID().uuidString).appendingPathExtension("gif")
do {
// Write GIF data to temporary file
try gifData.write(to: tempFileURL)
// Insert the GIF directly as a standard attachment into the message field
conversation.insertAttachment(tempFileURL, withAlternateFilename: "animated.gif") { error in
if let error = error {
self.showErrorAlert(error: error)
} else {
// Successfully inserted the attachment
self.requestPresentationStyle(.compact)
}
}
} catch {
self.showErrorAlert(error: error)
}
}
}
}
}
private func showErrorAlert(error: Error? = nil, message: String? = nil) {
let errorMessage = message ?? error?.localizedDescription ?? "An unknown error occurred"
let alertController = UIAlertController(title: "Error", message: errorMessage, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default))
present(alertController, animated: true)
}
// MARK: - Conversation Handling
override func willBecomeActive(with conversation: MSConversation) {
// Called when the extension is about to move from the inactive to active state.
// This will happen when the extension is about to present UI.
// Refresh GIFs list when becoming active
gifCollectionVC?.viewWillAppear(true)
// We don't need to check for custom message URLs anymore since
// we're sending standard GIF attachments
}
override func didResignActive(with conversation: MSConversation) {
// Called when the extension is about to move from the active to inactive state.
// This will happen when the user dismisses the extension, changes to a different
// conversation or quits Messages.
// Use this method to release shared resources, save user data, invalidate timers,
// and store enough state information to restore your extension to its current state
// in case it is terminated later.
}
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
// Called when a message arrives that was generated by another instance of this
// extension on a remote device.
// Since we're now sending GIFs as standard attachments rather than
// custom messages, we don't need special handling for received messages
}
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {
// Called when the user taps the send button.
}
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {
// Called when the user deletes the message without sending it.
// Use this to clean up state related to the deleted message.
}
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
// Called before the extension transitions to a new presentation style.
// Use this method to prepare for the change in presentation style.
}
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
// Called after the extension transitions to a new presentation style.
// Use this method to finalize any behaviors associated with the change in presentation style.
}
}

View File

@@ -1,22 +0,0 @@
import Foundation
import UIKit
struct GIF: Codable, Identifiable, Equatable {
let id: UUID
let urlString: String
let createdAt: Date
var url: URL? {
return URL(string: urlString)
}
init(urlString: String) {
self.id = UUID()
self.urlString = urlString
self.createdAt = Date()
}
static func == (lhs: GIF, rhs: GIF) -> Bool {
return lhs.id == rhs.id
}
}

View File

@@ -1,49 +0,0 @@
import Foundation
class GIFStorageService {
static let shared = GIFStorageService()
private let userDefaults = UserDefaults(suiteName: "group.gifcollector")
private let savedGIFsKey = "savedGIFs"
private init() {
// Make sure the shared UserDefaults exists
if userDefaults == nil {
print("Error: Could not create UserDefaults with app group")
}
}
func saveGIF(_ gif: GIF) {
var savedGIFs = fetchGIFs()
// Don't save duplicate URLs
if !savedGIFs.contains(where: { $0.urlString == gif.urlString }) {
savedGIFs.append(gif)
saveToUserDefaults(gifs: savedGIFs)
}
}
func fetchGIFs() -> [GIF] {
guard let data = userDefaults?.data(forKey: savedGIFsKey),
let gifs = try? JSONDecoder().decode([GIF].self, from: data) else {
return []
}
return gifs.sorted(by: { $0.createdAt > $1.createdAt })
}
func deleteGIF(with id: UUID) {
var savedGIFs = fetchGIFs()
savedGIFs.removeAll(where: { $0.id == id })
saveToUserDefaults(gifs: savedGIFs)
}
func clearAllGIFs() {
saveToUserDefaults(gifs: [])
}
private func saveToUserDefaults(gifs: [GIF]) {
guard let data = try? JSONEncoder().encode(gifs) else { return }
userDefaults?.set(data, forKey: savedGIFsKey)
}
}

View File

@@ -1,486 +0,0 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 77;
objects = {
/* Begin PBXBuildFile section */
1B3192822DEDCF86007850B9 /* GIFCollector MessagesExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 1B3192812DEDCF86007850B9 /* GIFCollector MessagesExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1B3192872DEDCF86007850B9 /* Messages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B3192862DEDCF86007850B9 /* Messages.framework */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
1B3192832DEDCF86007850B9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1B3192722DEDCF83007850B9 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 1B3192802DEDCF86007850B9;
remoteInfo = "GIFCollector MessagesExtension";
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
1B3192972DEDCF87007850B9 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
1B3192822DEDCF86007850B9 /* GIFCollector MessagesExtension.appex in Embed Foundation Extensions */,
);
name = "Embed Foundation Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1B3192782DEDCF83007850B9 /* GIFCollector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GIFCollector.app; sourceTree = BUILT_PRODUCTS_DIR; };
1B3192812DEDCF86007850B9 /* GIFCollector MessagesExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "GIFCollector MessagesExtension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
1B3192862DEDCF86007850B9 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = System/Library/Frameworks/Messages.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
1B3192912DEDCF87007850B9 /* Exceptions for "GIFCollector MessagesExtension" folder in "GIFCollector MessagesExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 1B3192802DEDCF86007850B9 /* GIFCollector MessagesExtension */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
1B31927A2DEDCF83007850B9 /* GIFCollector */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = GIFCollector;
sourceTree = "<group>";
};
1B3192882DEDCF86007850B9 /* GIFCollector MessagesExtension */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
1B3192912DEDCF87007850B9 /* Exceptions for "GIFCollector MessagesExtension" folder in "GIFCollector MessagesExtension" target */,
);
path = "GIFCollector MessagesExtension";
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
1B31927E2DEDCF86007850B9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1B3192872DEDCF86007850B9 /* Messages.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
1B3192712DEDCF83007850B9 = {
isa = PBXGroup;
children = (
1B31927A2DEDCF83007850B9 /* GIFCollector */,
1B3192882DEDCF86007850B9 /* GIFCollector MessagesExtension */,
1B3192852DEDCF86007850B9 /* Frameworks */,
1B3192792DEDCF83007850B9 /* Products */,
);
sourceTree = "<group>";
};
1B3192792DEDCF83007850B9 /* Products */ = {
isa = PBXGroup;
children = (
1B3192782DEDCF83007850B9 /* GIFCollector.app */,
1B3192812DEDCF86007850B9 /* GIFCollector MessagesExtension.appex */,
);
name = Products;
sourceTree = "<group>";
};
1B3192852DEDCF86007850B9 /* Frameworks */ = {
isa = PBXGroup;
children = (
1B3192862DEDCF86007850B9 /* Messages.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
1B3192772DEDCF83007850B9 /* GIFCollector */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1B3192982DEDCF87007850B9 /* Build configuration list for PBXNativeTarget "GIFCollector" */;
buildPhases = (
1B3192762DEDCF83007850B9 /* Resources */,
1B3192972DEDCF87007850B9 /* Embed Foundation Extensions */,
);
buildRules = (
);
dependencies = (
1B3192842DEDCF86007850B9 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
1B31927A2DEDCF83007850B9 /* GIFCollector */,
);
name = GIFCollector;
packageProductDependencies = (
);
productName = GIFCollector;
productReference = 1B3192782DEDCF83007850B9 /* GIFCollector.app */;
productType = "com.apple.product-type.application.messages";
};
1B3192802DEDCF86007850B9 /* GIFCollector MessagesExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1B3192922DEDCF87007850B9 /* Build configuration list for PBXNativeTarget "GIFCollector MessagesExtension" */;
buildPhases = (
1B31927D2DEDCF86007850B9 /* Sources */,
1B31927E2DEDCF86007850B9 /* Frameworks */,
1B31927F2DEDCF86007850B9 /* Resources */,
);
buildRules = (
);
dependencies = (
);
fileSystemSynchronizedGroups = (
1B3192882DEDCF86007850B9 /* GIFCollector MessagesExtension */,
);
name = "GIFCollector MessagesExtension";
packageProductDependencies = (
);
productName = "GIFCollector MessagesExtension";
productReference = 1B3192812DEDCF86007850B9 /* GIFCollector MessagesExtension.appex */;
productType = "com.apple.product-type.app-extension.messages";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
1B3192722DEDCF83007850B9 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1640;
LastUpgradeCheck = 1640;
TargetAttributes = {
1B3192772DEDCF83007850B9 = {
CreatedOnToolsVersion = 16.4;
};
1B3192802DEDCF86007850B9 = {
CreatedOnToolsVersion = 16.4;
};
};
};
buildConfigurationList = 1B3192752DEDCF83007850B9 /* Build configuration list for PBXProject "GIFCollector" */;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 1B3192712DEDCF83007850B9;
minimizedProjectReferenceProxies = 1;
preferredProjectObjectVersion = 77;
productRefGroup = 1B3192792DEDCF83007850B9 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
1B3192772DEDCF83007850B9 /* GIFCollector */,
1B3192802DEDCF86007850B9 /* GIFCollector MessagesExtension */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
1B3192762DEDCF83007850B9 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1B31927F2DEDCF86007850B9 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
1B31927D2DEDCF86007850B9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
1B3192842DEDCF86007850B9 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 1B3192802DEDCF86007850B9 /* GIFCollector MessagesExtension */;
targetProxy = 1B3192832DEDCF86007850B9 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
1B3192932DEDCF87007850B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "GIFCollector MessagesExtension/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.MessagesExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
1B3192942DEDCF87007850B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "GIFCollector MessagesExtension/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector.MessagesExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
1B3192952DEDCF87007850B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
1B3192962DEDCF87007850B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.5;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
1B3192992DEDCF87007850B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
1B31929A2DEDCF87007850B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "GIF Collector";
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.abunchofknowitalls.GIFCollector;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1B3192752DEDCF83007850B9 /* Build configuration list for PBXProject "GIFCollector" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B3192952DEDCF87007850B9 /* Debug */,
1B3192962DEDCF87007850B9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1B3192922DEDCF87007850B9 /* Build configuration list for PBXNativeTarget "GIFCollector MessagesExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B3192932DEDCF87007850B9 /* Debug */,
1B3192942DEDCF87007850B9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1B3192982DEDCF87007850B9 /* Build configuration list for PBXNativeTarget "GIFCollector" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1B3192992DEDCF87007850B9 /* Debug */,
1B31929A2DEDCF87007850B9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 1B3192722DEDCF83007850B9 /* Project object */;
}

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,315 @@
import SwiftUI
import UIKit
import UniformTypeIdentifiers
struct ContentView: View {
@State private var gifs: [GIF] = []
@State private var showingAddGIF = false
@State private var showingAlert = false
@State private var alertTitle = ""
@State private var alertMessage = ""
// For handling app lifecycle notifications
@Environment(\.scenePhase) private var scenePhase
var body: some View {
NavigationView {
ZStack {
if gifs.isEmpty {
VStack {
Text("No GIFs saved")
.font(.headline)
Text("Add your first GIF using the + button")
.font(.subheadline)
.foregroundColor(.secondary)
}
} else {
ScrollView {
LazyVGrid(
columns: [
GridItem(.flexible(), spacing: 10),
GridItem(.flexible(), spacing: 10),
], spacing: 10
) {
ForEach(gifs) { gif in
GIFCell(
gif: gif,
onTap: {
copyGIFToClipboard(gif)
},
onDelete: {
deleteGIF(gif)
})
}
}
.padding()
}
}
}
.navigationTitle("GIF Collector")
.toolbar {
Button(action: {
showingAddGIF = true
}) {
Image(systemName: "plus.circle.fill")
.resizable()
.frame(width: 24, height: 24)
}
}
.sheet(isPresented: $showingAddGIF) {
AddGIFView { urlString, gifData in
saveGIF(urlString: urlString, data: gifData)
showingAddGIF = false
} onCancel: {
showingAddGIF = false
}
}
.alert(isPresented: $showingAlert) {
Alert(
title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("OK")))
}
.onAppear {
loadGIFs()
// Register for foreground notification
NotificationCenter.default.addObserver(
forName: UIApplication.willEnterForegroundNotification,
object: nil,
queue: .main
) { _ in
loadGIFs()
}
}
.onDisappear {
// Remove notification observer when view disappears
NotificationCenter.default.removeObserver(
self,
name: UIApplication.willEnterForegroundNotification,
object: nil
)
}
// Also monitor scene phase changes
.onChange(of: scenePhase) { newPhase in
if newPhase == .active {
loadGIFs()
}
}
}
}
private func loadGIFs() {
// Check for shared GIFs on app launch
GIFStorageService.shared.checkForSharedGIFs()
gifs = GIFStorageService.shared.fetchGIFs()
}
private func saveGIF(urlString: String, data: Data) {
GIFStorageService.shared.saveGIF(data: data, fromURL: urlString) { _ in
loadGIFs()
}
}
private func deleteGIF(_ gif: GIF) {
print("Got delete request for \(gif.id)")
GIFStorageService.shared.deleteGIF(with: gif.id)
loadGIFs()
}
private func copyGIFToClipboard(_ gif: GIF) {
guard let data = GIFStorageService.shared.getGIFData(for: gif) else {
showAlert(title: "Error", message: "Could not load GIF data")
return
}
let pasteboard = UIPasteboard.general
pasteboard.setData(data, forPasteboardType: UTType.gif.identifier)
showAlert(title: "Copied!", message: "GIF copied to clipboard")
}
private func showAlert(title: String, message: String) {
alertTitle = title
alertMessage = message
showingAlert = true
}
}
struct GIFCell: View {
let gif: GIF
let onTap: () -> Void
let onDelete: () -> Void
@State private var showingDeleteConfirmation = false
var body: some View {
ZStack {
GIFPlayerUIView(filePath: gif.localFilePath)
.aspectRatio(1, contentMode: .fill)
.cornerRadius(8)
// Tap hint overlay
Color.black.opacity(0.0001) // Almost transparent for hit testing
}
.aspectRatio(1, contentMode: .fit)
.cornerRadius(8)
.clipped()
.shadow(radius: 2)
.onTapGesture {
onTap()
}
.contextMenu {
Button(
role: .destructive,
action: {
onDelete()
}
) {
Label("Delete", systemImage: "trash")
}
Button(action: {
onTap()
}) {
Label("Copy to Clipboard", systemImage: "doc.on.clipboard")
}
}
}
}
struct GIFPlayerUIView: UIViewRepresentable {
let filePath: String
func makeUIView(context: Context) -> UIView {
let view = UIView()
let gifPlayerView = GIFPlayerView(frame: view.bounds)
gifPlayerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(gifPlayerView)
if let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)) {
gifPlayerView.loadGIF(from: data)
gifPlayerView.startAnimating()
}
return view
}
func updateUIView(_ uiView: UIView, context: Context) {
// Nothing to update
}
}
struct AddGIFView: View {
@State private var urlString = ""
@State private var isLoading = false
@State private var previewData: Data?
@State private var showError = false
@State private var errorMessage = ""
let onSave: (String, Data) -> Void
let onCancel: () -> Void
var body: some View {
NavigationView {
VStack(spacing: 20) {
TextField("Enter GIF URL", text: $urlString)
.textFieldStyle(RoundedBorderTextFieldStyle())
.autocapitalization(.none)
.disableAutocorrection(true)
.onChange(of: urlString) { _ in
if !urlString.isEmpty {
loadPreview()
} else {
previewData = nil
}
}
if isLoading {
ProgressView()
.frame(height: 200)
} else if let data = previewData {
GIFPreview(data: data)
.frame(height: 200)
.cornerRadius(8)
} else {
Rectangle()
.fill(Color.gray.opacity(0.2))
.frame(height: 200)
.cornerRadius(8)
.overlay(
Text("GIF Preview")
.foregroundColor(.gray)
)
}
Spacer()
}
.padding()
.navigationTitle("Add New GIF")
.navigationBarItems(
leading: Button("Cancel") {
onCancel()
},
trailing: Button("Save") {
if let data = previewData {
onSave(urlString, data)
}
}
.disabled(previewData == nil)
)
.alert(isPresented: $showError) {
Alert(
title: Text("Error"), message: Text(errorMessage), dismissButton: .default(Text("OK")))
}
}
}
private func loadPreview() {
guard URL(string: urlString) != nil else {
return
}
isLoading = true
previewData = nil
DownloadService.shared.downloadGIF(from: urlString) { data, error in
isLoading = false
if let error = error {
errorMessage = error.localizedDescription
showError = true
return
}
if let data = data {
previewData = data
} else {
errorMessage = "Failed to load GIF"
showError = true
}
}
}
}
struct GIFPreview: UIViewRepresentable {
let data: Data
func makeUIView(context: Context) -> UIView {
let view = UIView()
let gifPlayerView = GIFPlayerView(frame: view.bounds)
gifPlayerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(gifPlayerView)
gifPlayerView.loadGIF(from: data)
gifPlayerView.startAnimating()
return view
}
func updateUIView(_ uiView: UIView, context: Context) {
// Nothing to update
}
}
#Preview {
ContentView()
}

34
GIFCollector/GIF.swift Normal file
View File

@@ -0,0 +1,34 @@
import Foundation
// Removed SwiftData dependency to ensure compatibility across targets
struct GIF: Codable, Identifiable, Equatable {
let id: UUID
let localFilePath: String
let originalURL: String
let createdAt: Date
var fileURL: URL? {
return URL(fileURLWithPath: localFilePath)
}
init(localFilePath: String, originalURL: String) {
self.id = UUID()
self.localFilePath = localFilePath
self.originalURL = originalURL
self.createdAt = Date()
}
init(localFilePath: String, originalURL: String, id: UUID, createdAt: Date) {
self.id = id
self.localFilePath = localFilePath
self.originalURL = originalURL
self.createdAt = createdAt
}
// For equality comparison
static func == (lhs: GIF, rhs: GIF) -> Bool {
return lhs.id == rhs.id
}
}

View File

@@ -24,7 +24,7 @@ class GIFCollectionViewCell: UICollectionViewCell {
return label
}()
private var currentTask: URLSessionDataTask?
private var gifData: Data?
override init(frame: CGRect) {
super.init(frame: frame)
@@ -38,8 +38,7 @@ class GIFCollectionViewCell: UICollectionViewCell {
override func prepareForReuse() {
super.prepareForReuse()
currentTask?.cancel()
currentTask = nil
gifData = nil
gifPlayerView.stopAnimating()
placeholderLabel.isHidden = false
loadingIndicator.stopAnimating()
@@ -68,40 +67,35 @@ class GIFCollectionViewCell: UICollectionViewCell {
])
contentView.layer.cornerRadius = 8
contentView.layer.borderWidth = 1
contentView.layer.borderColor = UIColor.systemGray4.cgColor
}
func configure(with urlString: String) {
// Cancel any existing task
currentTask?.cancel()
func configure(with gif: GIF) {
// Reset UI
gifPlayerView.stopAnimating()
placeholderLabel.isHidden = false
loadingIndicator.startAnimating()
guard let url = URL(string: urlString) else {
loadingIndicator.stopAnimating()
return
}
// Load the GIF
currentTask = URLSession.shared.dataTask(with: url) { [weak self] data, _, error in
DispatchQueue.main.async {
guard let self = self else { return }
self.loadingIndicator.stopAnimating()
// Load the GIF data from local storage
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
if let gifData = GIFStorageService.shared.getGIFData(for: gif) {
if let data = data, error == nil {
self.gifPlayerView.loadGIF(from: data)
DispatchQueue.main.async {
guard let self = self else { return }
self.loadingIndicator.stopAnimating()
self.gifData = gifData
self.gifPlayerView.loadGIF(from: gifData)
self.gifPlayerView.startAnimating()
self.placeholderLabel.isHidden = true
} else {
}
} else {
DispatchQueue.main.async {
guard let self = self else { return }
self.loadingIndicator.stopAnimating()
self.placeholderLabel.isHidden = false
}
}
}
currentTask?.resume()
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.abunchofknowitalls.GIFCollector</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,16 @@
import SwiftUI
@main
struct GIFCollectorApp: App {
init() {
// Initialize any services here
let _ = GIFStorageService.shared
let _ = GIFFileManager.shared
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

View File

@@ -1,19 +1,19 @@
import Foundation
import UIKit
class GIFDownloadService {
static let shared = GIFDownloadService()
class DownloadService {
static let shared = DownloadService()
private let cache = NSCache<NSString, NSData>()
private var activeTasks: [URL: URLSessionDataTask] = [:]
private init() {
cache.totalCostLimit = 100 * 1024 * 1024 // 100 MB cache limit
cache.totalCostLimit = 50 * 1024 * 1024 // 50 MB cache limit
}
func downloadGIF(from urlString: String, completion: @escaping (Data?, Error?) -> Void) {
guard let url = URL(string: urlString) else {
completion(nil, NSError(domain: "GIFDownloadService", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
completion(nil, NSError(domain: "DownloadService", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
return
}
@@ -35,7 +35,7 @@ class GIFDownloadService {
guard let self = self, error == nil, let data = data else {
DispatchQueue.main.async {
completion(nil, error ?? NSError(domain: "GIFDownloadService", code: 2, userInfo: [NSLocalizedDescriptionKey: "Failed to download GIF"]))
completion(nil, error ?? NSError(domain: "DownloadService", code: 2, userInfo: [NSLocalizedDescriptionKey: "Failed to download GIF"]))
}
return
}

View File

@@ -0,0 +1,181 @@
import Foundation
import UIKit
var appGroupID = "group."+Bundle.main.bundleIdentifier.unsafelyUnwrapped.replacing(".iMessage", with:"")
class GIFFileManager {
static let shared = GIFFileManager()
private init() {
createGIFsDirectoryIfNeeded()
}
// MARK: - File Storage
// Always use the App Group container for consistent storage between extensions
private var documentsDirectory: URL {
if let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID) {
return containerURL
} else {
// This should only happen if App Group capability is not properly set up
print("ERROR: App Group container not available. GIFs will not be shared between extensions!")
// Fall back to the app's documents directory if App Group is not available
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
}
private var gifsDirectory: URL {
// Use a consistent folder name for GIFs across all extensions
return documentsDirectory.appendingPathComponent("SharedGIFs", isDirectory: true)
}
private func createGIFsDirectoryIfNeeded() {
let fileManager = FileManager.default
if !fileManager.fileExists(atPath: gifsDirectory.path) {
do {
try fileManager.createDirectory(at: gifsDirectory, withIntermediateDirectories: true)
print("Created shared GIFs directory at: \(gifsDirectory.path)")
} catch {
print("Error creating shared GIFs directory: \(error)")
}
} else {
print("Using existing shared GIFs directory at: \(gifsDirectory.path)")
}
}
func storeGIF(data: Data, fromURL urlString: String) -> String? {
// Check if this is a shared GIF from the share extension
if let sharedGIFPath = checkForSharedGIF(withURL: urlString), FileManager.default.fileExists(atPath: sharedGIFPath) {
return sharedGIFPath
}
// Create a unique filename based on the URL hash and timestamp
let urlHash = urlString.hashValue
let timestamp = Int(Date().timeIntervalSince1970)
let filename = "gif_\(urlHash)_\(timestamp).gif"
let fileURL = gifsDirectory.appendingPathComponent(filename)
do {
try data.write(to: fileURL)
return fileURL.path
} catch {
print("Error saving GIF to disk: \(error)")
return nil
}
}
func loadGIFData(from localPath: String) -> Data? {
let url = URL(fileURLWithPath: localPath)
do {
let data = try Data(contentsOf: url)
return data
} catch {
print("Error loading GIF from disk: \(error)")
return nil
}
}
func deleteGIF(at localPath: String) -> Bool {
let fileManager = FileManager.default
do {
try fileManager.removeItem(atPath: localPath)
return true
} catch {
print("Error deleting GIF from disk: \(error)")
return false
}
}
func fileExists(at localPath: String) -> Bool {
return FileManager.default.fileExists(atPath: localPath)
}
func getAllGIFsSize() -> Int64 {
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(at: gifsDirectory, includingPropertiesForKeys: [.fileSizeKey])
var totalSize: Int64 = 0
while let fileURL = enumerator?.nextObject() as? URL {
do {
let attributes = try fileURL.resourceValues(forKeys: [.fileSizeKey])
if let fileSize = attributes.fileSize {
totalSize += Int64(fileSize)
}
} catch {
print("Error calculating file size: \(error)")
}
}
return totalSize
}
// Clean up old GIFs if storage exceeds 100 MB
func performStorageCleanupIfNeeded() {
let maxStorageSize: Int64 = 100 * 1024 * 1024 // 100 MB
if getAllGIFsSize() > maxStorageSize {
cleanupOldGIFs()
}
}
private func cleanupOldGIFs() {
let fileManager = FileManager.default
do {
// Get all files and their creation dates
let fileURLs = try fileManager.contentsOfDirectory(at: gifsDirectory, includingPropertiesForKeys: [.creationDateKey])
// Sort by creation date
let sortedFiles = try fileURLs.sorted {
let date1 = try $0.resourceValues(forKeys: [.creationDateKey]).creationDate ?? Date.distantPast
let date2 = try $1.resourceValues(forKeys: [.creationDateKey]).creationDate ?? Date.distantPast
return date1 < date2
}
// Delete the oldest 30% of files
let filesToDelete = Int(Double(sortedFiles.count) * 0.3)
for i in 0..<min(filesToDelete, sortedFiles.count) {
try fileManager.removeItem(at: sortedFiles[i])
}
} catch {
print("Error cleaning up old GIFs: \(error)")
}
}
// Check if we already have this GIF in the shared container
private func checkForSharedGIF(withURL urlString: String) -> String? {
// Use our standard gifsDirectory property instead of recreating the path
guard FileManager.default.fileExists(atPath: gifsDirectory.path) else {
return nil
}
do {
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: appGroupID)
if let pendingGIFs = userDefaults?.array(forKey: "pendingGIFs") as? [[String: Any]] {
for gifInfo in pendingGIFs {
if let originURL = gifInfo["originalURL"] as? String,
let path = gifInfo["localFilePath"] as? String,
originURL == urlString {
return path
}
}
}
return nil
} catch {
print("Error checking for shared GIFs: \(error)")
return nil
}
}
}

View File

@@ -0,0 +1,219 @@
import Foundation
class GIFStorageService {
static let shared = GIFStorageService()
// Use constant App Group ID to ensure consistency across targets
private let userDefaults = UserDefaults(suiteName: appGroupID)
// Use a consistent key for saved GIFs across all extensions
private let savedGIFsKey = "sharedGIFs"
private let pendingGIFsKey = "pendingGIFs"
private init() {
// Make sure the shared UserDefaults exists
if userDefaults == nil {
print("ERROR: Could not create UserDefaults with app group. GIFs will not be shared between extensions!")
} else {
print("Successfully connected to shared UserDefaults")
}
// Process any pending GIFs from the Share Extension
checkForSharedGIFs()
// Log the number of GIFs found
let count = fetchGIFs().count
print("Found \(count) GIFs in shared storage")
}
func saveGIF(data: Data, fromURL urlString: String, completion: @escaping (GIF?) -> Void) {
// First store the GIF data to disk
guard let localPath = GIFFileManager.shared.storeGIF(data: data, fromURL: urlString) else {
completion(nil)
return
}
// Create and save the GIF model
let gif = GIF(localFilePath: localPath, originalURL: urlString)
var savedGIFs = fetchGIFs()
// Don't save duplicates of the same URL
if !savedGIFs.contains(where: { $0.originalURL == urlString }) {
savedGIFs.append(gif)
saveToUserDefaults(gifs: savedGIFs)
}
// Perform cleanup if needed
GIFFileManager.shared.performStorageCleanupIfNeeded()
completion(gif)
}
func fetchGIFs() -> [GIF] {
guard let userDefaultsInstance = userDefaults else {
print("ERROR: UserDefaults is nil, cannot fetch GIFs")
return []
}
guard let data = userDefaultsInstance.data(forKey: savedGIFsKey) else {
print("No GIFs data found in UserDefaults for key: \(savedGIFsKey)")
return []
}
do {
let gifs = try JSONDecoder().decode([GIF].self, from: data)
print("Fetched \(gifs.count) GIFs from shared storage")
// Debug IDs
if !gifs.isEmpty {
print("GIF IDs: \(gifs.map { $0.id.uuidString.prefix(8) }.joined(separator: ", "))")
}
// Filter out any GIFs whose files no longer exist
let validGIFs = gifs.filter {
let exists = GIFFileManager.shared.fileExists(at: $0.localFilePath)
if !exists {
print("Warning: GIF file not found at path: \($0.localFilePath)")
}
return exists
}
// If we filtered any out, save the updated list
if validGIFs.count != gifs.count {
print("Removed \(gifs.count - validGIFs.count) invalid GIFs from storage")
saveToUserDefaults(gifs: validGIFs)
}
return validGIFs.sorted(by: { $0.createdAt > $1.createdAt })
} catch {
print("ERROR: Failed to decode GIFs from UserDefaults: \(error)")
return []
}
}
func deleteGIF(with id: UUID) {
var savedGIFs = fetchGIFs()
// Find the GIF to delete
if let gifToDelete = savedGIFs.first(where: { $0.id == id }) {
print("Deleting GIF with ID: \(id), path: \(gifToDelete.localFilePath)")
// Delete the file from storage
let fileDeleted = GIFFileManager.shared.deleteGIF(at: gifToDelete.localFilePath)
if fileDeleted {
print("Successfully deleted GIF file from storage")
} else {
print("Warning: Failed to delete GIF file at path: \(gifToDelete.localFilePath)")
}
// Remove from the list regardless of whether file deletion succeeded
let countBefore = savedGIFs.count
savedGIFs.removeAll(where: { $0.id == id })
if savedGIFs.count < countBefore {
print("Removed GIF from saved list, count before: \(countBefore), after: \(savedGIFs.count)")
saveToUserDefaults(gifs: savedGIFs)
} else {
print("Error: GIF with ID \(id) was not found in memory array")
}
} else {
print("Error: Could not find GIF with ID \(id) to delete")
}
}
func clearAllGIFs() {
// Delete all GIF files
fetchGIFs().forEach { gif in
GIFFileManager.shared.deleteGIF(at: gif.localFilePath)
}
// Clear the list
saveToUserDefaults(gifs: [])
}
private func saveToUserDefaults(gifs: [GIF]) {
do {
let data = try JSONEncoder().encode(gifs)
userDefaults?.set(data, forKey: savedGIFsKey)
print("Successfully saved \(gifs.count) GIFs to shared storage")
// Force UserDefaults to synchronize to ensure immediate visibility across extensions
if userDefaults?.synchronize() == true {
print("UserDefaults successfully synchronized")
} else {
print("Warning: UserDefaults synchronize may have failed")
}
// Double-check that our changes were actually saved
if let checkData = userDefaults?.data(forKey: savedGIFsKey),
let checkGifs = try? JSONDecoder().decode([GIF].self, from: checkData) {
print("Verified: \(checkGifs.count) GIFs stored in UserDefaults")
} else {
print("ERROR: Failed to verify GIFs were saved to UserDefaults")
}
} catch {
print("ERROR: Failed to encode GIFs for storage: \(error)")
}
}
func getGIFData(for gif: GIF) -> Data? {
return GIFFileManager.shared.loadGIFData(from: gif.localFilePath)
}
// MARK: - Share Extension Integration
func checkForSharedGIFs() {
guard let pendingGIFsData = userDefaults?.array(forKey: pendingGIFsKey) as? [[String: Any]] else {
print("No pending GIFs found in shared storage")
return
}
guard !pendingGIFsData.isEmpty else {
print("Pending GIFs array is empty")
return
}
print("Found \(pendingGIFsData.count) pending GIFs to process")
var savedGIFs = fetchGIFs()
var newGIFsAdded = false
for gifInfo in pendingGIFsData {
if let localFilePath = gifInfo["localFilePath"] as? String,
let originalURL = gifInfo["originalURL"] as? String,
let createdAt = gifInfo["createdAt"] as? TimeInterval {
// Create a GIF object - use the provided ID if available, or create a new one
let gifId = (gifInfo["id"] as? String).flatMap { UUID(uuidString: $0) } ?? UUID()
let gifCreatedAt = Date(timeIntervalSince1970: createdAt)
let gif = GIF(
localFilePath: localFilePath,
originalURL: originalURL,
id: gifId,
createdAt: gifCreatedAt
)
// Don't add duplicates
if !savedGIFs.contains(where: { $0.localFilePath == localFilePath }) {
savedGIFs.append(gif)
newGIFsAdded = true
}
}
}
// Save updated GIFs list and clear pending ones
if newGIFsAdded {
print("Added \(pendingGIFsData.count) new GIFs from shared extension")
saveToUserDefaults(gifs: savedGIFs)
} else {
print("No new GIFs were added from pending list")
}
// Clear pending GIFs
userDefaults?.removeObject(forKey: pendingGIFsKey)
userDefaults?.synchronize()
print("Cleared pending GIFs from shared storage")
}
}

View File

@@ -22,8 +22,6 @@ class AddGIFViewController: UIViewController {
return textField
}()
private let previewGIFPlayer: GIFPlayerView = {
let player = GIFPlayerView()
player.clipsToBounds = true
@@ -56,8 +54,9 @@ class AddGIFViewController: UIViewController {
return button
}()
private var currentTask: URLSessionDataTask?
var onSaveGIF: ((GIF) -> Void)?
private var currentTask: Any?
private var downloadedGIFData: Data?
var onSaveGIF: ((String, Data) -> Void)?
var onCancel: (() -> Void)?
override func viewDidLoad() {
@@ -91,7 +90,7 @@ class AddGIFViewController: UIViewController {
urlTextField.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 16),
urlTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
urlTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
previewGIFPlayer.topAnchor.constraint(equalTo: urlTextField.bottomAnchor, constant: 16),
previewGIFPlayer.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
previewGIFPlayer.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
@@ -113,12 +112,12 @@ class AddGIFViewController: UIViewController {
}
private func setupActions() {
urlTextField.delegate = self
urlTextField.addTarget(self, action: #selector(urlTextDidChange), for: .editingChanged)
saveButton.addTarget(self, action: #selector(saveButtonTapped), for: .touchUpInside)
cancelButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside)
urlTextField.delegate = self
urlTextField.addTarget(self, action: #selector(urlTextDidChange), for: .editingChanged)
saveButton.addTarget(self, action: #selector(saveButtonTapped), for: .touchUpInside)
cancelButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside)
}
@objc private func urlTextDidChange() {
@@ -132,10 +131,13 @@ class AddGIFViewController: UIViewController {
}
private func loadGIFPreview(from urlString: String) {
// Cancel any existing task
currentTask?.cancel()
// Cancel any existing task if needed
if let task = currentTask as? URLSessionTask {
task.cancel()
}
currentTask = nil
guard let url = URL(string: urlString) else {
guard URL(string: urlString) != nil else {
saveButton.isEnabled = false
return
}
@@ -143,33 +145,34 @@ class AddGIFViewController: UIViewController {
loadingIndicator.startAnimating()
previewGIFPlayer.stopAnimating()
currentTask = URLSession.shared.dataTask(with: url) { [weak self] data, _, error in
DownloadService.shared.downloadGIF(from: urlString) { [weak self] data, error in
DispatchQueue.main.async {
guard let self = self else { return }
self.loadingIndicator.stopAnimating()
if let data = data, error == nil {
self.downloadedGIFData = data
self.previewGIFPlayer.loadGIF(from: data)
self.previewGIFPlayer.startAnimating()
self.saveButton.isEnabled = true
} else {
self.downloadedGIFData = nil
self.previewGIFPlayer.stopAnimating()
self.saveButton.isEnabled = false
}
}
}
currentTask?.resume()
}
@objc private func saveButtonTapped() {
guard let urlString = urlTextField.text, !urlString.isEmpty else { return }
let gif = GIF(urlString: urlString)
onSaveGIF?(gif)
dismiss(animated: true)
guard let urlString = urlTextField.text,
!urlString.isEmpty,
let gifData = downloadedGIFData
else { return }
onSaveGIF?(urlString, gifData)
dismiss(animated: true)
}
@objc private func cancelButtonTapped() {
@@ -179,8 +182,8 @@ class AddGIFViewController: UIViewController {
}
extension AddGIFViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}

View File

@@ -16,6 +16,7 @@ class GIFCollectionViewController: UIViewController {
super.viewDidLoad()
setupCollectionView()
setupUI()
setupGestureRecognizers()
loadGIFs()
}
@@ -41,6 +42,11 @@ class GIFCollectionViewController: UIViewController {
collectionView.dataSource = self
collectionView.register(GIFCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
collectionView.alwaysBounceVertical = true
if #available(iOS 14.0, *) {
// Use collection view's built-in contextual menu support
// This is set up in collectionView(_:contextMenuConfigurationForItemAt:point:)
}
}
private func setupUI() {
@@ -51,8 +57,9 @@ class GIFCollectionViewController: UIViewController {
collectionView.translatesAutoresizingMaskIntoConstraints = false
// Setup Add Button
addButton.setImage(UIImage(systemName: "plus.circle.fill"), for: .normal)
addButton.setImage(UIImage(systemName: "plus.circle.fill", withConfiguration: UIImage.SymbolConfiguration(paletteColors: [UIColor.white, .systemBlue])), for: .normal)
addButton.tintColor = .systemBlue
addButton.configuration?.baseForegroundColor = UIColor.white
addButton.contentHorizontalAlignment = .fill
addButton.contentVerticalAlignment = .fill
addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside)
@@ -87,7 +94,7 @@ class GIFCollectionViewController: UIViewController {
updateEmptyState()
}
private func loadGIFs() {
func loadGIFs() {
gifs = GIFStorageService.shared.fetchGIFs()
collectionView.reloadData()
updateEmptyState()
@@ -99,9 +106,12 @@ class GIFCollectionViewController: UIViewController {
@objc private func addButtonTapped() {
let addGIFVC = AddGIFViewController()
addGIFVC.onSaveGIF = { [weak self] gif in
GIFStorageService.shared.saveGIF(gif)
self?.loadGIFs()
addGIFVC.onSaveGIF = { [weak self] urlString, gifData in
GIFStorageService.shared.saveGIF(data: gifData, fromURL: urlString) { _ in
DispatchQueue.main.async {
self?.loadGIFs()
}
}
}
addGIFVC.onCancel = { [weak self] in
self?.dismiss(animated: true)
@@ -111,6 +121,53 @@ class GIFCollectionViewController: UIViewController {
navController.modalPresentationStyle = .formSheet
present(navController, animated: true)
}
private func setupGestureRecognizers() {
// For iOS versions earlier than 14, we'll use a long press gesture recognizer
if #unavailable(iOS 14.0) {
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:)))
collectionView.addGestureRecognizer(longPressGesture)
}
}
@objc private func handleLongPress(_ gesture: UILongPressGestureRecognizer) {
if gesture.state == .began {
let point = gesture.location(in: collectionView)
guard let indexPath = collectionView.indexPathForItem(at: point) else { return }
// Show action sheet for pre-iOS 14 devices
showDeleteActionSheet(for: indexPath)
}
}
private func showDeleteActionSheet(for indexPath: IndexPath) {
let gif = gifs[indexPath.item]
let alertController = UIAlertController(
title: "GIF Options",
message: "What would you like to do with this GIF?",
preferredStyle: .actionSheet
)
alertController.addAction(UIAlertAction(title: "Delete", style: .destructive) { [weak self] _ in
self?.deleteGIF(at: indexPath)
})
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
present(alertController, animated: true)
}
private func deleteGIF(at indexPath: IndexPath) {
let gif = gifs[indexPath.item]
GIFStorageService.shared.deleteGIF(with: gif.id)
// Remove from local array and update collection view
gifs.remove(at: indexPath.item)
collectionView.deleteItems(at: [indexPath])
updateEmptyState()
}
}
extension GIFCollectionViewController: UICollectionViewDelegate, UICollectionViewDataSource {
@@ -124,7 +181,7 @@ extension GIFCollectionViewController: UICollectionViewDelegate, UICollectionVie
}
let gif = gifs[indexPath.item]
cell.configure(with: gif.urlString)
cell.configure(with: gif)
return cell
}
@@ -133,4 +190,23 @@ extension GIFCollectionViewController: UICollectionViewDelegate, UICollectionVie
let gif = gifs[indexPath.item]
onSelectGIF?(gif)
}
}
// MARK: - Context Menu Support (iOS 14+)
@available(iOS 14.0, *)
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let gif = gifs[indexPath.item]
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
let deleteAction = UIAction(
title: "Delete",
image: UIImage(systemName: "trash"),
attributes: .destructive
) { [weak self] _ in
self?.deleteGIF(at: indexPath)
}
return UIMenu(title: "", children: [deleteAction])
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.abunchofknowitalls.GIFCollector</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,120 @@
//
// MessagesViewController.swift
// GIFCollector MessagesExtension
//
// Created by Joshua Higgins on 6/2/25.
//
import Messages
import UIKit
class MessagesViewController: MSMessagesAppViewController {
private var gifCollectionVC: GIFCollectionViewController?
override func viewDidLoad() {
super.viewDidLoad()
setupChildViewController()
// Register for notifications when app becomes active
NotificationCenter.default.addObserver(self,
selector: #selector(appDidBecomeActive),
name: UIApplication.didBecomeActiveNotification,
object: nil)
}
private func setupChildViewController() {
let collectionVC = GIFCollectionViewController()
collectionVC.onSelectGIF = { [weak self] gif in
self?.sendGIF(gif)
}
addChild(collectionVC)
collectionVC.view.frame = view.bounds
collectionVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(collectionVC.view)
collectionVC.didMove(toParent: self)
gifCollectionVC = collectionVC
}
private func sendGIF(_ gif: GIF) {
guard let conversation = activeConversation else { return }
// Show a loading indicator
let loadingAlert = UIAlertController(title: "Preparing GIF", message: "Please wait...", preferredStyle: .alert)
present(loadingAlert, animated: true)
// Load the GIF data from local storage
DispatchQueue.global(qos: .userInitiated).async {
let gifData = GIFStorageService.shared.getGIFData(for: gif)
DispatchQueue.main.async {
// Dismiss the loading indicator
self.dismiss(animated: true) {
guard let gifData = gifData else {
self.showErrorAlert(message: "Failed to load GIF from storage")
return
}
// Create a temporary file URL for the GIF
let tempDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let tempFileURL = tempDirectoryURL.appendingPathComponent(UUID().uuidString).appendingPathExtension("gif")
do {
// Write GIF data to temporary file
try gifData.write(to: tempFileURL)
// Insert the GIF directly as a standard attachment into the message field
conversation.insertAttachment(tempFileURL, withAlternateFilename: "animated.gif") { error in
if let error = error {
self.showErrorAlert(error: error)
} else {
// Successfully inserted the attachment
self.requestPresentationStyle(.compact)
}
}
} catch {
self.showErrorAlert(error: error)
}
}
}
}
}
private func showErrorAlert(error: Error? = nil, message: String? = nil) {
let errorMessage = message ?? error?.localizedDescription ?? "An unknown error occurred"
let alertController = UIAlertController(
title: "Error", message: errorMessage, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default))
present(alertController, animated: true)
}
// MARK: - Conversation Handling
override func willBecomeActive(with conversation: MSConversation) {
// Called when the extension is about to move from the inactive to active state.
// This will happen when the extension is about to present UI.
// Check for GIFs shared from the Share Extension
GIFStorageService.shared.checkForSharedGIFs()
// Refresh GIFs list when becoming active
gifCollectionVC?.viewWillAppear(true)
}
override func didResignActive(with conversation: MSConversation) {
// No action needed when the extension becomes inactive
}
@objc private func appDidBecomeActive() {
// Check for GIFs shared through the Share Extension
GIFStorageService.shared.checkForSharedGIFs()
gifCollectionVC?.loadGIFs()
}
override func didReceive(_ message: MSMessage, conversation: MSConversation) {}
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {}
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {}
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {}
}

View File

Before

Width:  |  Height:  |  Size: 261 KiB

After

Width:  |  Height:  |  Size: 261 KiB

View File

Before

Width:  |  Height:  |  Size: 387 KiB

After

Width:  |  Height:  |  Size: 387 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="j1y-V4-xli">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Share View Controller-->
<scene sceneID="ceB-am-kn3">
<objects>
<viewController id="j1y-V4-xli" customClass="ShareViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" opaque="NO" contentMode="scaleToFill" id="wbc-yd-nQP">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="1Xd-am-t49"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CEy-Cv-SGf" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.abunchofknowitalls.GIFCollector</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
(
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &quot;com.compuserve.gif&quot;
)
).@count == $extensionItem.attachments.@count
).@count == 1</string>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,354 @@
//
// ShareViewController.swift
// GIFCollectorShare
//
import MobileCoreServices
import Social
import UIKit
import UniformTypeIdentifiers
class ShareViewController: SLComposeServiceViewController {
private var receivedURL: URL?
private var gifData: Data?
private var isProcessing = false
private var originalURL: String = ""
private var debugMessages: [String] = []
// Use the same constants as in the main app
private let appGroupID = "group."+Bundle.main.bundleIdentifier.unsafelyUnwrapped.replacing(".Share", with:"")
private let pendingGIFsKey = "pendingGIFs"
override func viewDidLoad() {
super.viewDidLoad()
title = "Save to GIF Collector"
placeholder = "Add a note (optional)"
// Add debug button in development
#if DEBUG
let debugButton = UIBarButtonItem(
title: "Debug", style: .plain, target: self, action: #selector(showDebugInfo))
navigationItem.leftBarButtonItem = debugButton
#endif
// Start processing the shared item
processSharedItem()
addDebugMessage("ShareViewController loaded")
}
override func isContentValid() -> Bool {
// No validation needed for the text field, we just want the GIF
return true
}
override func didSelectPost() {
// Show loading
isProcessing = true
navigationController?.navigationBar.isUserInteractionEnabled = false
// If we have a URL but no data, we need to download it
if let receivedURL = receivedURL, gifData == nil {
downloadGIF(from: receivedURL) { [weak self] data, error in
guard let self = self else { return }
if let data = data {
self.gifData = data
self.saveGIF()
} else {
self.showError(
message: "Could not download GIF: \(error?.localizedDescription ?? "Unknown error")")
}
}
} else if let gifData = gifData {
// We already have the data, save it directly
saveGIF()
} else {
// No valid GIF was found
showError(message: "No valid GIF found in the shared content")
}
}
override func didSelectCancel() {
// User canceled, close the extension
completeRequest()
}
// MARK: - Private Methods
private func processSharedItem() {
addDebugMessage("Starting to process shared item")
// Log extension context info
if let context = extensionContext {
addDebugMessage("Extension context exists")
addDebugMessage("Input items count: \(context.inputItems.count)")
} else {
addDebugMessage("Extension context is nil")
}
guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem else {
addDebugMessage("No extension item found")
showError(message: "No shared content found")
return
}
guard let attachments = extensionItem.attachments else {
addDebugMessage("No attachments found")
showError(message: "No attachments found")
return
}
addDebugMessage("Found \(attachments.count) attachments")
// Process each attachment
for attachment in attachments {
// Log attachment types
let typeIdentifiers = attachment.registeredTypeIdentifiers
addDebugMessage("Attachment types: \(typeIdentifiers.joined(separator: ", "))")
// Check for URLs first (for web links to GIFs)
if attachment.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
addDebugMessage("Processing URL type attachment")
attachment.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) {
[weak self] item, error in
guard let self = self else { return }
if let url = item as? URL, url.absoluteString.lowercased().hasSuffix(".gif") {
DispatchQueue.main.async {
self.receivedURL = url
self.originalURL = url.absoluteString
self.updateUI()
}
} else if let url = item as? URL {
// It's a URL but not directly to a GIF, might be a webpage containing a GIF
DispatchQueue.main.async {
self.originalURL = url.absoluteString
self.receivedURL = url
self.updateUI()
self.addDebugMessage("URL processed: \(url.absoluteString)")
}
}
}
continue
}
// Check for GIF files
if attachment.hasItemConformingToTypeIdentifier("com.compuserve.gif")
|| attachment.hasItemConformingToTypeIdentifier("public.gif")
{
addDebugMessage("Processing GIF type attachment")
attachment.loadItem(forTypeIdentifier: "com.compuserve.gif", options: nil) {
[weak self] item, error in
guard let self = self else { return }
if let url = item as? URL {
DispatchQueue.main.async {
self.receivedURL = url
self.originalURL = url.absoluteString
self.loadGIFData(from: url)
self.updateUI()
}
} else if let data = item as? Data {
DispatchQueue.main.async {
self.gifData = data
self.updateUI()
}
}
}
continue
}
// Check for images that might be GIFs
if attachment.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
attachment.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) {
[weak self] item, error in
guard let self = self else { return }
if let url = item as? URL, url.pathExtension.lowercased() == "gif" {
DispatchQueue.main.async {
self.receivedURL = url
self.originalURL = url.absoluteString
self.loadGIFData(from: url)
self.updateUI()
}
} else if let data = item as? Data, self.isGIFData(data) {
DispatchQueue.main.async {
self.gifData = data
self.updateUI()
}
}
}
}
}
}
private func updateUI() {
// Enable the Post button if we have a URL or data
navigationItem.rightBarButtonItem?.isEnabled = (receivedURL != nil || gifData != nil)
// Update content area
if let url = receivedURL {
let displayText = "GIF from: \(url.host ?? "URL")"
if contentText.isEmpty {
}
}
}
private func loadGIFData(from url: URL) {
do {
let data = try Data(contentsOf: url)
if isGIFData(data) {
gifData = data
}
} catch {
print("Error loading GIF data: \(error)")
}
}
private func isGIFData(_ data: Data) -> Bool {
// Simple check for GIF file signature: "GIF87a" or "GIF89a"
guard data.count > 6 else { return false }
let header = data.prefix(6)
let gif87a = Data([0x47, 0x49, 0x46, 0x38, 0x37, 0x61]) // "GIF87a"
let gif89a = Data([0x47, 0x49, 0x46, 0x38, 0x39, 0x61]) // "GIF89a"
return header == gif87a || header == gif89a
}
private func downloadGIF(from url: URL, completion: @escaping (Data?, Error?) -> Void) {
URLSession.shared.dataTask(with: url) { data, response, error in
DispatchQueue.main.async {
if let data = data, self.isGIFData(data) {
completion(data, nil)
} else {
completion(
nil,
error
?? NSError(
domain: "GIFShare", code: -1,
userInfo: [NSLocalizedDescriptionKey: "Invalid GIF data"]))
}
}
}.resume()
}
private func saveGIF() {
guard let gifData = gifData else {
showError(message: "No GIF data to save")
return
}
addDebugMessage("Starting to save GIF, size: \(gifData.count) bytes")
// Save the GIF using the shared App Group container
let userDefaults = UserDefaults(suiteName: appGroupID)
let fileManager = FileManager.default
// IMPORTANT: Use the same path conventions as GIFFileManager
guard
let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)
else {
showError(message: "Could not access shared container")
return
}
// Use the same folder name as in GIFFileManager
let gifsFolder = containerURL.appendingPathComponent("SharedGIFs", isDirectory: true)
// Create GIFs directory if needed
if !fileManager.fileExists(atPath: gifsFolder.path) {
do {
try fileManager.createDirectory(at: gifsFolder, withIntermediateDirectories: true)
addDebugMessage("Created shared GIFs directory")
} catch {
showError(message: "Could not create GIFs directory: \(error.localizedDescription)")
return
}
}
// Create a unique filename using the same pattern as GIFFileManager
let urlHash = originalURL.hashValue
let timestamp = Int(Date().timeIntervalSince1970)
let filename = "gif_\(urlHash)_\(timestamp).gif"
let fileURL = gifsFolder.appendingPathComponent(filename)
// Save the GIF file
do {
try gifData.write(to: fileURL)
addDebugMessage("GIF saved to: \(fileURL.path)")
// Create a UUID that will be used consistently across the app
let gifId = UUID()
// Store GIF entry in UserDefaults to notify main app
let gifInfo: [String: Any] = [
"localFilePath": fileURL.path,
"originalURL": originalURL,
"createdAt": Date().timeIntervalSince1970,
"id": gifId.uuidString,
]
// Add to pending GIFs list (using the same key as in GIFStorageService)
var pendingGIFs = userDefaults?.array(forKey: pendingGIFsKey) as? [[String: Any]] ?? []
pendingGIFs.append(gifInfo)
userDefaults?.set(pendingGIFs, forKey: pendingGIFsKey)
// Force synchronize to ensure changes are visible immediately
userDefaults?.synchronize()
addDebugMessage("GIF info saved to UserDefaults")
// Success
completeRequest()
} catch {
showError(message: "Error saving GIF: \(error.localizedDescription)")
}
}
private func addDebugMessage(_ message: String) {
let timestamp = DateFormatter.localizedString(
from: Date(), dateStyle: .none, timeStyle: .medium)
debugMessages.append("[\(timestamp)] \(message)")
print("GIFCollector Debug: \(message)")
}
@objc private func showDebugInfo() {
let debugText = debugMessages.joined(separator: "\n\n")
let alert = UIAlertController(
title: "Debug Information", message: debugText, preferredStyle: .alert)
alert.addAction(
UIAlertAction(title: "Copy", style: .default) { _ in
UIPasteboard.general.string = debugText
})
alert.addAction(UIAlertAction(title: "OK", style: .cancel))
present(alert, animated: true)
}
private func showError(message: String) {
addDebugMessage("ERROR: \(message)")
let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
alert.addAction(
UIAlertAction(title: "OK", style: .default) { [weak self] _ in
self?.completeRequest()
})
// Add debug info button
#if DEBUG
alert.addAction(
UIAlertAction(title: "Debug Info", style: .default) { [weak self] _ in
self?.showDebugInfo()
})
#endif
present(alert, animated: true)
}
private func completeRequest() {
addDebugMessage("Completing extension request")
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}
}