Skip to content

Commit

Permalink
Use visionOS SDK instead iOS SDK. (#24)
Browse files Browse the repository at this point in the history
* Enabled visionOS SDK

* In visionOS, use openURL.

ref: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller

* .safari

* Update README.md

* Revert ".safari"

This reverts commit 812357e.

* Update trySwift.swift

* run openURL

* syntax
  • Loading branch information
noppefoxwolf committed Mar 14, 2024
1 parent ab2fe76 commit 3b8c07d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 40 deletions.
18 changes: 11 additions & 7 deletions App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
D583D7CA2B9B634800B94F73 /* ClipApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D583D7C92B9B634800B94F73 /* ClipApp.swift */; };
D583D7CE2B9B634B00B94F73 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D583D7CD2B9B634B00B94F73 /* Assets.xcassets */; };
D583D7D12B9B634B00B94F73 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D583D7D02B9B634B00B94F73 /* Preview Assets.xcassets */; };
D583D7D62B9B634B00B94F73 /* Clip.app in Embed App Clips */ = {isa = PBXBuildFile; fileRef = D583D7C72B9B634800B94F73 /* Clip.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
D583D7D62B9B634B00B94F73 /* Clip.app in Embed App Clips */ = {isa = PBXBuildFile; fileRef = D583D7C72B9B634800B94F73 /* Clip.app */; platformFilters = (ios, macos, ); settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
D583D7DC2B9B639900B94F73 /* AppFeature in Frameworks */ = {isa = PBXBuildFile; productRef = D583D7DB2B9B639900B94F73 /* AppFeature */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -273,6 +273,10 @@
/* Begin PBXTargetDependency section */
D583D7D52B9B634B00B94F73 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilters = (
ios,
macos,
);
target = D583D7C62B9B634800B94F73 /* Clip */;
targetProxy = D583D7D42B9B634B00B94F73 /* PBXContainerItemProxy */;
};
Expand Down Expand Up @@ -439,12 +443,12 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.tryswift.tokyo.App;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand Down Expand Up @@ -484,12 +488,12 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.tryswift.tokyo.App;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion MyLibrary/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "MyLibrary",
defaultLocalization: "en",
platforms: [.iOS(.v17), .macOS(.v14), .watchOS(.v10), .tvOS(.v17)],
platforms: [.iOS(.v17), .macOS(.v14), .watchOS(.v10), .tvOS(.v17), .visionOS(.v1)],
products: [
.library(
name: "AppFeature",
Expand Down
6 changes: 6 additions & 0 deletions MyLibrary/Sources/ScheduleFeature/Detail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public struct ScheduleDetail {
public enum Destination {
case safari(Safari)
}

@Dependency(\.openURL) var openURL

public init() {}

Expand All @@ -47,8 +49,12 @@ public struct ScheduleDetail {
Reduce { state, action in
switch action {
case let .view(.snsTapped(url)):
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .destination:
return .none
case .binding:
Expand Down
5 changes: 5 additions & 0 deletions MyLibrary/Sources/ScheduleFeature/Schedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ public struct Schedule {
return .none
case .view(.mapItemTapped):
let url = URL(string: String(localized: "Guidance URL", bundle: .module))!
#if os(iOS) || os(macOS)
state.destination = .guidance(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .binding, .path, .destination:
return .none
}
Expand All @@ -102,6 +106,7 @@ public struct Schedule {
public struct ScheduleView: View {

@Bindable public var store: StoreOf<Schedule>

let mapTip: MapTip = .init()

public init(store: StoreOf<Schedule>) {
Expand Down
4 changes: 4 additions & 0 deletions MyLibrary/Sources/SponsorFeature/Sponsors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public struct SponsorsList {

case let .view(.sponsorTapped(sponsor)):
guard let url = sponsor.link else { return .none }
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .binding:
return .none
case .destination:
Expand Down
6 changes: 6 additions & 0 deletions MyLibrary/Sources/trySwiftFeature/Acknowledgements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ public struct Acknowledgements {
case urlTapped(URL)
case safari(PresentationAction<Safari.Action>)
}

@Dependency(\.openURL) var openURL

public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case let .urlTapped(url):
#if os(iOS) || os(macOS)
state.safari = .init(url: url)
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .safari:
return .none
}
Expand Down
6 changes: 6 additions & 0 deletions MyLibrary/Sources/trySwiftFeature/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ public struct Profile {
case safari(Safari)
}

@Dependency(\.openURL) var openURL

public init() {}

public var body: some ReducerOf<Self> {
BindingReducer()
Reduce { state, action in
switch action {
case let .view(.snsTapped(url)):
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .destination:
return .none
case .binding:
Expand Down
55 changes: 24 additions & 31 deletions MyLibrary/Sources/trySwiftFeature/trySwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ public struct TrySwift {

@Reducer(state: .equatable)
public enum Destination {
case codeOfConduct(Safari)
case privacyPolicy(Safari)
case eventbrite(Safari)
case website(Safari)
case safari(Safari)
}

@Dependency(\.openURL) var openURL

public init() {}

Expand All @@ -55,23 +54,39 @@ public struct TrySwift {
return .none
case .view(.codeOfConductTapped):
let url = URL(string: String(localized: "Code of Conduct URL", bundle: .module))!
state.destination = .codeOfConduct(.init(url: url))
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .view(.privacyPolicyTapped):
let url = URL(string: String(localized: "Privacy Policy URL", bundle: .module))!
state.destination = .privacyPolicy(.init(url: url))
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .view(.acknowledgementsTapped):
state.path.append(.acknowledgements(.init()))
return .none
case .view(.eventbriteTapped):
let url = URL(string: String(localized: "Eventbrite URL", bundle: .module))!
state.destination = .eventbrite(.init(url: url))
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case .view(.websiteTapped):
let url = URL(string: String(localized: "Website URL", bundle: .module))!
state.destination = .eventbrite(.init(url: url))
#if os(iOS) || os(macOS)
state.destination = .safari(.init(url: url))
return .none
#elseif os(visionOS)
return .run { _ in await openURL(url) }
#endif
case let .path(.element(_, .organizers(.delegate(.organizerTapped(organizer))))):
state.path.append(.profile(.init(organizer: organizer)))
return .none
Expand Down Expand Up @@ -171,32 +186,10 @@ public struct TrySwiftView: View {
}
.navigationTitle(Text("try! Swift", bundle: .module))
.sheet(
item: $store.scope(state: \.destination?.codeOfConduct, action: \.destination.codeOfConduct)
item: $store.scope(state: \.destination?.safari, action: \.destination.safari)
) { sheetStore in
SafariViewRepresentation(url: sheetStore.url)
.ignoresSafeArea()
.navigationTitle(Text("Code of Conduct", bundle: .module))
}
.sheet(
item: $store.scope(state: \.destination?.privacyPolicy, action: \.destination.privacyPolicy),
content: { sheetStore in
SafariViewRepresentation(url: sheetStore.url)
.ignoresSafeArea()
.navigationTitle(Text("Privacy Policy", bundle: .module))
}
)
.sheet(
item: $store.scope(state: \.destination?.eventbrite, action: \.destination.eventbrite),
content: { sheetStore in
SafariViewRepresentation(url: sheetStore.url)
.ignoresSafeArea()
}
)
.sheet(
item: $store.scope(state: \.destination?.website, action: \.destination.website),
content: { sheetStore in
SafariViewRepresentation(url: sheetStore.url)
.ignoresSafeArea()
})
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We've submitted the app to the App Store as MVP, and it's currently under review
- [ ] macOS support
- [ ] watchOS support
- [ ] tvOS support
- [x] visionOS support (Designed for iPad)
- [x] visionOS support

## Requirements

Expand Down

0 comments on commit 3b8c07d

Please sign in to comment.