From f5cfc92c03aa282f0d7beb87d51e0f00fe563c52 Mon Sep 17 00:00:00 2001 From: David Walter Date: Sun, 20 Oct 2024 10:50:25 +0200 Subject: [PATCH] Fix Alert Button not triggering action when running on non-iOS platforms Fixes #29 --- Demo/Demo.xcodeproj/project.pbxproj | 12 ++++++++++-- Demo/Demo/ContentView.swift | 1 + Demo/Demo/Demo.entitlements | 10 ++++++++++ .../Extensions/ProcessInfoExtensions.swift | 18 ++++++++++++++++++ .../Helper/OnSimultaneousTapGesture.swift | 14 ++++++++++++-- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 Demo/Demo/Demo.entitlements create mode 100644 Sources/CustomAlert/Extensions/ProcessInfoExtensions.swift diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 10ea23f..d5e5aa2 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 630CF3DE2C39B52500B6FF68 /* DetailLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailLabel.swift; sourceTree = ""; }; 630CF3E12C39B6E400B6FF68 /* CustomAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAlerts.swift; sourceTree = ""; }; 630CF3E32C39B6ED00B6FF68 /* SimpleAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleAlerts.swift; sourceTree = ""; }; + 6332AEB02CC4F19A00C4A1BC /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = ""; }; 6364916028AFEAFB00FA518B /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6364916328AFEAFB00FA518B /* DemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoApp.swift; sourceTree = ""; }; 6364916528AFEAFB00FA518B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -80,6 +81,7 @@ 6364916228AFEAFB00FA518B /* Demo */ = { isa = PBXGroup; children = ( + 6332AEB02CC4F19A00C4A1BC /* Demo.entitlements */, 6364916328AFEAFB00FA518B /* DemoApp.swift */, 6364916528AFEAFB00FA518B /* ContentView.swift */, 630CF3E02C39B68F00B6FF68 /* Alerts */, @@ -321,6 +323,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = Demo/Demo.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -342,9 +345,11 @@ PRODUCT_BUNDLE_IDENTIFIER = at.davidwalter.CustomAlert.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -353,6 +358,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = Demo/Demo.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -374,9 +380,11 @@ PRODUCT_BUNDLE_IDENTIFIER = at.davidwalter.CustomAlert.Demo; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/Demo/Demo/ContentView.swift b/Demo/Demo/ContentView.swift index e8cc97c..2a71822 100644 --- a/Demo/Demo/ContentView.swift +++ b/Demo/Demo/ContentView.swift @@ -23,6 +23,7 @@ struct ContentView: View { } .navigationTitle("Custom Alert") } + .navigationViewStyle(.stack) } } diff --git a/Demo/Demo/Demo.entitlements b/Demo/Demo/Demo.entitlements new file mode 100644 index 0000000..ee95ab7 --- /dev/null +++ b/Demo/Demo/Demo.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/Sources/CustomAlert/Extensions/ProcessInfoExtensions.swift b/Sources/CustomAlert/Extensions/ProcessInfoExtensions.swift new file mode 100644 index 0000000..3e7729a --- /dev/null +++ b/Sources/CustomAlert/Extensions/ProcessInfoExtensions.swift @@ -0,0 +1,18 @@ +// +// ProcessInfoExtensions.swift +// CustomAlert +// +// Created by David Walter on 20.10.24. +// + +import Foundation + +extension ProcessInfo { + var isiOSAppOnVision: Bool { + NSClassFromString("UIWindowSceneGeometryPreferencesVision") != nil + } + + var isiOSAppOnOtherPlatform: Bool { + isiOSAppOnMac || isMacCatalystApp || isiOSAppOnVision + } +} diff --git a/Sources/CustomAlert/Helper/OnSimultaneousTapGesture.swift b/Sources/CustomAlert/Helper/OnSimultaneousTapGesture.swift index 54c7805..6707a86 100644 --- a/Sources/CustomAlert/Helper/OnSimultaneousTapGesture.swift +++ b/Sources/CustomAlert/Helper/OnSimultaneousTapGesture.swift @@ -39,8 +39,18 @@ private struct SimultaneousTapGestureViewModifier: ViewModifier { ) #else if #available(iOS 18.0, *) { - content - .simultaneousGesture(simultaneousTapGesture) + if ProcessInfo.processInfo.isiOSAppOnOtherPlatform { + content + .overlay( + SimultaneousTapGesture( + numberOfTapsRequired: count, + action: action + ) + ) + } else { + content + .simultaneousGesture(simultaneousTapGesture) + } } else { content .overlay(