Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for visionOS. #80

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Connectivity.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Connectivity wraps Apple's Reachability code to provide a reliable measure of wh
s.ios.deployment_target = '12.0'
s.tvos.deployment_target = '12.0'
s.macos.deployment_target = '10.13'
s.visionos.deployment_target = '1.0'
s.frameworks = 'SystemConfiguration'
s.weak_frameworks = 'Network', 'Combine'
s.source_files = 'Connectivity/Classes/**/*'
Expand Down
14 changes: 7 additions & 7 deletions Connectivity/Classes/Connectivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public extension Connectivity {
}
}

@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
private func startPathMonitorNotifier() {
let monitor = NWPathMonitor()
pathMonitor = monitor
Expand Down Expand Up @@ -298,7 +298,7 @@ public extension Connectivity {
isObservingInterfaceChanges = false
}

@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
private func stopPathMonitorNotifier() {
if isObservingInterfaceChanges, let monitor = pathMonitor as? NWPathMonitor {
monitor.cancel()
Expand Down Expand Up @@ -491,7 +491,7 @@ private extension Connectivity {
}
}

@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
func interface(from path: NWPath) -> ConnectivityInterface {
if path.usesInterfaceType(.wifi) {
return .wifi
Expand All @@ -504,7 +504,7 @@ private extension Connectivity {
}
}

@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
func interfaces(from path: NWPath) -> [ConnectivityInterface] {
return path.availableInterfaces.map { interface in
switch interface.type {
Expand Down Expand Up @@ -579,7 +579,7 @@ private extension Connectivity {
}

/// Maps a NetworkStatus to a NWInterface.InterfaceType, if possible.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
private func interfaceType(from networkStatus: NetworkStatus) -> NWInterface.InterfaceType? {
switch networkStatus {
case ReachableViaWiFi:
Expand Down Expand Up @@ -670,7 +670,7 @@ private extension Connectivity {
}

/// Determines the connectivity status using network interface info provided by `NWPath`.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
func status(from path: NWPath, isConnected: Bool) -> ConnectivityStatus {
switch interface(from: path) {
case .cellular:
Expand All @@ -693,7 +693,7 @@ private extension Connectivity {
}

/// Updates the connectivity status using network interface info provided by `NWPath`.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, *)
@available(OSX 10.14, iOS 12.0, tvOS 12.0, visionOS 1.0, *)
func updateStatus(from path: NWPath, isConnected: Bool) {
availableInterfaces = interfaces(from: path)
currentInterface = interface(from: path)
Expand Down
212 changes: 211 additions & 1 deletion Example/Connectivity.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5F1BD1A24AA051100D10B24"
BuildableName = "Connectivity_Example_macOS.app"
BlueprintName = "Connectivity_Example_macOS"
ReferencedContainer = "container:Connectivity.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 = "D5F1BD1A24AA051100D10B24"
BuildableName = "Connectivity_Example_macOS.app"
BlueprintName = "Connectivity_Example_macOS"
ReferencedContainer = "container:Connectivity.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D5F1BD1A24AA051100D10B24"
BuildableName = "Connectivity_Example_macOS.app"
BlueprintName = "Connectivity_Example_macOS"
ReferencedContainer = "container:Connectivity.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FCD2C9042AC1B7F400441914"
BuildableName = "Connectivity_Example_visionOS.app"
BlueprintName = "Connectivity_Example_visionOS"
ReferencedContainer = "container:Connectivity.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 = "FCD2C9042AC1B7F400441914"
BuildableName = "Connectivity_Example_visionOS.app"
BlueprintName = "Connectivity_Example_visionOS"
ReferencedContainer = "container:Connectivity.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FCD2C9042AC1B7F400441914"
BuildableName = "Connectivity_Example_visionOS.app"
BlueprintName = "Connectivity_Example_visionOS"
ReferencedContainer = "container:Connectivity.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.solidimagestacklayer"
},
{
"filename" : "Middle.solidimagestacklayer"
},
{
"filename" : "Back.solidimagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "reality",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
18 changes: 18 additions & 0 deletions Example/Connectivity_Example_visionOS/ConnectivityExampleApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ConnectivityExampleApp.swift
// Connectivity_Example_visionOS
//
// Created by Zandor Smith on 25/09/2023.
// Copyright © 2023 CocoaPods. All rights reserved.
//

import SwiftUI

@main
struct ConnectivityExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
35 changes: 35 additions & 0 deletions Example/Connectivity_Example_visionOS/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ContentView.swift
// Connectivity_Example_visionOS
//
// Created by Zandor Smith on 25/09/2023.
// Copyright © 2023 CocoaPods. All rights reserved.
//

import SwiftUI
import Connectivity

struct ContentView: View {
private let connectivity = Connectivity(shouldUseHTTPS: false)

var body: some View {
VStack {
Text("Hello, world!")
}
.padding()
.onAppear(perform: {
connectivity.framework = .network
connectivity.whenConnected = { connectivity in
print("connectivity11", connectivity.status.description)
}
connectivity.whenDisconnected = { connectivity in
print("connectivity12", connectivity.status.description)
}
connectivity.startNotifier()
})
}
}

#Preview(windowStyle: .automatic) {
ContentView()
}
15 changes: 15 additions & 0 deletions Example/Connectivity_Example_visionOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationPreferredDefaultSceneSessionRole</key>
<string>UIWindowSceneSessionRoleApplication</string>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict/>
</dict>
</dict>
</plist>
4 changes: 4 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ end
target 'Connectivity_Example_macOS' do
connectivity
end

target 'Connectivity_Example_visionOS' do
connectivity
end
Loading