Skip to content

Commit

Permalink
Fix Alert Button not triggering action when running on non-iOS platforms
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
divadretlaw committed Oct 20, 2024
1 parent f1fd435 commit f5cfc92
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
630CF3DE2C39B52500B6FF68 /* DetailLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailLabel.swift; sourceTree = "<group>"; };
630CF3E12C39B6E400B6FF68 /* CustomAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAlerts.swift; sourceTree = "<group>"; };
630CF3E32C39B6ED00B6FF68 /* SimpleAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleAlerts.swift; sourceTree = "<group>"; };
6332AEB02CC4F19A00C4A1BC /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = "<group>"; };
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 = "<group>"; };
6364916528AFEAFB00FA518B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -80,6 +81,7 @@
6364916228AFEAFB00FA518B /* Demo */ = {
isa = PBXGroup;
children = (
6332AEB02CC4F19A00C4A1BC /* Demo.entitlements */,
6364916328AFEAFB00FA518B /* DemoApp.swift */,
6364916528AFEAFB00FA518B /* ContentView.swift */,
630CF3E02C39B68F00B6FF68 /* Alerts */,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};
Expand All @@ -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;
Expand All @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions Demo/Demo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ContentView: View {
}
.navigationTitle("Custom Alert")
}
.navigationViewStyle(.stack)
}
}

Expand Down
10 changes: 10 additions & 0 deletions Demo/Demo/Demo.entitlements
Original file line number Diff line number Diff line change
@@ -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.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
18 changes: 18 additions & 0 deletions Sources/CustomAlert/Extensions/ProcessInfoExtensions.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 12 additions & 2 deletions Sources/CustomAlert/Helper/OnSimultaneousTapGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f5cfc92

Please sign in to comment.