From 43be0a68ae42ac7ef67b712f22a778308cc58b39 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Wed, 15 Nov 2023 12:19:18 +0100 Subject: [PATCH] fix: weak link VisionKit to fix crash when running on iOS 16 --- Mastodon.xcodeproj/project.pbxproj | 4 ++++ .../MediaPreview/Image/MediaPreviewImageView.swift | 4 +++- .../Sources/MastodonExtension/ImageAnalyzer.swift | 12 ------------ 3 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 MastodonSDK/Sources/MastodonExtension/ImageAnalyzer.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 3ffb0d3102..d18c449dac 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -51,6 +51,7 @@ 2A9D0664298C048800BF38CB /* LatestFollowersWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9D0663298C048800BF38CB /* LatestFollowersWidget.swift */; }; 2A9D0666298C05A800BF38CB /* LatestFollowersWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9D0665298C05A800BF38CB /* LatestFollowersWidgetView.swift */; }; 2A9D066F298D0FD100BF38CB /* MastodonSDKDynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 2A9D066E298D0FD100BF38CB /* MastodonSDKDynamic */; }; + 2AAAA34E2B04DE21004C6672 /* VisionKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2AAAA34D2B04DE21004C6672 /* VisionKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 2AB12E4629362F27006BC925 /* DataSourceFacade+Translate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB12E4529362F27006BC925 /* DataSourceFacade+Translate.swift */; }; 2AB5011B2992322500346092 /* LightChart in Frameworks */ = {isa = PBXBuildFile; productRef = 2AB5011A2992322500346092 /* LightChart */; }; 2AB5011C299243FB00346092 /* WidgetExtension.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 2AB50120299243FB00346092 /* WidgetExtension.intentdefinition */; }; @@ -659,6 +660,7 @@ 2A86A14A2989326E007F1062 /* MultiFollowersCountWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiFollowersCountWidgetView.swift; sourceTree = ""; }; 2A9D0663298C048800BF38CB /* LatestFollowersWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatestFollowersWidget.swift; sourceTree = ""; }; 2A9D0665298C05A800BF38CB /* LatestFollowersWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatestFollowersWidgetView.swift; sourceTree = ""; }; + 2AAAA34D2B04DE21004C6672 /* VisionKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VisionKit.framework; path = System/Library/Frameworks/VisionKit.framework; sourceTree = SDKROOT; }; 2AB12E4529362F27006BC925 /* DataSourceFacade+Translate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+Translate.swift"; sourceTree = ""; }; 2AB5011F299243FB00346092 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/WidgetExtension.intentdefinition; sourceTree = ""; }; 2AB501222992440200346092 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/WidgetExtension.strings; sourceTree = ""; }; @@ -1294,6 +1296,7 @@ D84FA0932AE6915800987F47 /* MBProgressHUD in Frameworks */, D87364F92AE28DB500C8F919 /* Kanna in Frameworks */, 71458AF57697DB405CFEC37C /* Pods_Mastodon.framework in Frameworks */, + 2AAAA34E2B04DE21004C6672 /* VisionKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1734,6 +1737,7 @@ 3FE14AD363ED19AE7FF210A6 /* Frameworks */ = { isa = PBXGroup; children = ( + 2AAAA34D2B04DE21004C6672 /* VisionKit.framework */, DBF96325262EC0A6001D8D25 /* AuthenticationServices.framework */, DB8FAB9E26AEC3A2008E5AF4 /* Intents.framework */, DB8FABA926AEC3A2008E5AF4 /* IntentsUI.framework */, diff --git a/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift b/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift index f750e5a265..2469223279 100644 --- a/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift +++ b/Mastodon/Scene/MediaPreview/Image/MediaPreviewImageView.swift @@ -12,6 +12,8 @@ import VisionKit final class MediaPreviewImageView: UIScrollView { + private static let imageAnalyzer = ImageAnalyzer() + let imageView: FLAnimatedImageView = { let imageView = FLAnimatedImageView() imageView.contentMode = .scaleAspectFit @@ -140,7 +142,7 @@ extension MediaPreviewImageView { Task.detached(priority: .userInitiated) { do { - let analysis = try await ImageAnalyzer.shared.analyze(image, configuration: ImageAnalyzer.Configuration([.text, .machineReadableCode])) + let analysis = try await Self.imageAnalyzer.analyze(image, configuration: ImageAnalyzer.Configuration([.text, .machineReadableCode])) await MainActor.run { self.liveTextInteraction.analysis = analysis self.liveTextInteraction.preferredInteractionTypes = .automatic diff --git a/MastodonSDK/Sources/MastodonExtension/ImageAnalyzer.swift b/MastodonSDK/Sources/MastodonExtension/ImageAnalyzer.swift deleted file mode 100644 index 0ee05391b4..0000000000 --- a/MastodonSDK/Sources/MastodonExtension/ImageAnalyzer.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// ImageAnalyzer.swift -// -// -// Created by Jed Fox on 2022-11-14. -// - -import VisionKit - -extension ImageAnalyzer { - public static let shared = ImageAnalyzer() -}