@@ -23,104 +23,56 @@ namespace SystemConfiguration {
23
23
// CaptiveNetwork.h
24
24
public static partial class CaptiveNetwork {
25
25
26
- #if __TVOS__
27
- // in Xcode 10 the CaptiveNetwork API are marked as prohibited on tvOS
28
- #if ! NET
29
- [ Obsolete ( "Always return 'null'." ) ]
30
- [ Unavailable ( PlatformName . TvOS ) ]
31
- public static Foundation . NSString ? NetworkInfoKeyBSSID => null ;
32
-
33
- [ Obsolete ( "Always return 'null'." ) ]
34
- [ Unavailable ( PlatformName . TvOS ) ]
35
- public static Foundation . NSString ? NetworkInfoKeySSID => null ;
36
-
37
- [ Obsolete ( "Always return 'null'." ) ]
38
- [ Unavailable ( PlatformName . TvOS ) ]
39
- public static Foundation . NSString ? NetworkInfoKeySSIDData => null ;
40
-
41
- [ Obsolete ( "Throw a 'NotSupportedException'." ) ]
42
- [ Unavailable ( PlatformName . TvOS ) ]
43
- public static bool MarkPortalOffline ( string iface ) => throw new NotSupportedException ( ) ;
44
-
45
- [ Obsolete ( "Throw a 'NotSupportedException'." ) ]
46
- [ Unavailable ( PlatformName . TvOS ) ]
47
- public static bool MarkPortalOnline ( string iface ) => throw new NotSupportedException ( ) ;
48
-
49
- [ Obsolete ( "Throw a 'NotSupportedException'." ) ]
50
- [ Unavailable ( PlatformName . TvOS ) ]
51
- public static bool SetSupportedSSIDs ( string [ ] ssids ) => throw new NotSupportedException ( ) ;
52
-
53
- [ Obsolete ( "Throw a 'NotSupportedException'." ) ]
54
- [ Unavailable ( PlatformName . TvOS ) ]
55
- public static StatusCode TryCopyCurrentNetworkInfo ( string interfaceName , out Foundation . NSDictionary currentNetworkInfo ) => throw new NotSupportedException ( ) ;
56
-
57
- [ Obsolete ( "Throw a 'NotSupportedException'." ) ]
58
- [ Unavailable ( PlatformName . TvOS ) ]
59
- public static StatusCode TryGetSupportedInterfaces ( out string [ ] supportedInterfaces ) => throw new NotSupportedException ( ) ;
60
- #endif // !NET
61
- #else
62
-
26
+ #if ! __TVOS__
63
27
#if ! MONOMAC
64
-
65
- #if NET
66
28
[ SupportedOSPlatform ( "ios" ) ]
67
29
[ SupportedOSPlatform ( "maccatalyst" ) ]
68
30
[ ObsoletedOSPlatform ( "ios14.0" ) ]
69
31
[ ObsoletedOSPlatform ( "maccatalyst14.0" ) ]
70
- #else
71
- [ Deprecated ( PlatformName . iOS , 14 , 0 ) ]
72
- #endif
73
32
[ DllImport ( Constants . SystemConfigurationLibrary ) ]
74
33
extern static IntPtr /* CFDictionaryRef __nullable */ CNCopyCurrentNetworkInfo (
75
34
/* CFStringRef __nonnull */ IntPtr interfaceName ) ;
76
35
77
- #if NET
78
- /// <param name="interfaceName">To be added.</param>
79
- /// <param name="currentNetworkInfo">To be added.</param>
80
- /// <summary>To be added.</summary>
81
- /// <returns>To be added.</returns>
82
- /// <remarks>To be added.</remarks>
36
+ /// <summary>Copy the current network information into an <see cref="NSDictionary" />.</summary>
37
+ /// <param name="interfaceName">The name of the interface with the network information to copy.</param>
38
+ /// <param name="currentNetworkInfo">The copied network information upon return.</param>
39
+ /// <returns><see cref="StatusCode.OK" /> if successful, an error status otherwise.</returns>
83
40
[ SupportedOSPlatform ( "ios" ) ]
84
41
[ SupportedOSPlatform ( "maccatalyst" ) ]
85
42
[ ObsoletedOSPlatform ( "ios14.0" ) ]
86
43
[ ObsoletedOSPlatform ( "maccatalyst14.0" ) ]
87
- #else
88
- [ Deprecated ( PlatformName . iOS , 14 , 0 ) ]
89
- #endif
90
44
static public StatusCode TryCopyCurrentNetworkInfo ( string interfaceName , out NSDictionary ? currentNetworkInfo )
91
45
{
92
- using ( var nss = new NSString ( interfaceName ) ) {
93
- var ni = CNCopyCurrentNetworkInfo ( nss . Handle ) ;
94
- if ( ni == IntPtr . Zero ) {
95
- currentNetworkInfo = null ;
96
- return StatusCodeError . SCError ( ) ;
97
- }
98
-
99
- currentNetworkInfo = new NSDictionary ( ni ) ;
100
-
101
- // Must release since the IntPtr constructor calls Retain
102
- currentNetworkInfo . DangerousRelease ( ) ;
103
- return StatusCode . OK ;
46
+ if ( string . IsNullOrEmpty ( interfaceName ) )
47
+ ThrowHelper . ThrowArgumentNullException ( nameof ( interfaceName ) ) ;
48
+
49
+ using var nss = new TransientCFString ( interfaceName ) ;
50
+ var ni = CNCopyCurrentNetworkInfo ( nss ) ;
51
+ if ( ni == IntPtr . Zero ) {
52
+ currentNetworkInfo = null ;
53
+ return StatusCodeError . SCError ( ) ;
104
54
}
55
+
56
+ currentNetworkInfo = new NSDictionary ( ni ) ;
57
+
58
+ // Must release since the IntPtr constructor calls Retain
59
+ currentNetworkInfo . DangerousRelease ( ) ;
60
+ return StatusCode . OK ;
105
61
}
106
62
107
63
#endif
108
64
[ DllImport ( Constants . SystemConfigurationLibrary ) ]
109
65
extern static IntPtr /* CFArrayRef __nullable */ CNCopySupportedInterfaces ( ) ;
110
66
111
- #if NET
112
- /// <param name="supportedInterfaces">To be added.</param>
113
- /// <summary>To be added.</summary>
114
- /// <returns>To be added.</returns>
115
- /// <remarks>To be added.</remarks>
67
+ /// <summary>Fetch a list of the currently supported network interfaces.</summary>
68
+ /// <param name="supportedInterfaces">The list of supported network interfaces upon return.</param>
69
+ /// <returns><see cref="StatusCode.OK" /> if successful, an error status otherwise.</returns>
116
70
[ SupportedOSPlatform ( "macos" ) ]
117
71
[ SupportedOSPlatform ( "ios" ) ]
118
72
[ SupportedOSPlatform ( "maccatalyst" ) ]
119
- [ ObsoletedOSPlatform ( "maccatalyst13.1 " , "Use 'NEHotspotNetwork.FetchCurrent' instead." ) ]
73
+ [ ObsoletedOSPlatform ( "maccatalyst " , "Use 'NEHotspotNetwork.FetchCurrent' instead." ) ]
120
74
[ ObsoletedOSPlatform ( "ios14.0" , "Use 'NEHotspotNetwork.FetchCurrent' instead." ) ]
121
- #else
122
- [ Deprecated ( PlatformName . iOS , 14 , 0 , message : "Use 'NEHotspotNetwork.FetchCurrent' instead." ) ]
123
- #endif
75
+ // Not deprecated on macOS
124
76
static public StatusCode TryGetSupportedInterfaces ( out string ? [ ] ? supportedInterfaces )
125
77
{
126
78
IntPtr array = CNCopySupportedInterfaces ( ) ;
@@ -129,111 +81,89 @@ static public StatusCode TryGetSupportedInterfaces (out string? []? supportedInt
129
81
return StatusCodeError . SCError ( ) ;
130
82
}
131
83
132
- supportedInterfaces = CFArray . StringArrayFromHandle ( array ) ;
133
- CFObject . CFRelease ( array ) ;
84
+ supportedInterfaces = CFArray . StringArrayFromHandle ( array , true ) ;
134
85
return StatusCode . OK ;
135
86
}
136
87
137
- #if NET
138
88
[ SupportedOSPlatform ( "ios" ) ]
139
89
[ SupportedOSPlatform ( "macos" ) ]
140
90
[ SupportedOSPlatform ( "maccatalyst" ) ]
141
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
142
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
143
- #else
144
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
145
- #endif
91
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
92
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
93
+ // Not deprecated on macOS
146
94
[ DllImport ( Constants . SystemConfigurationLibrary ) ]
147
95
extern static byte CNMarkPortalOffline ( IntPtr /* CFStringRef __nonnull */ interfaceName ) ;
148
96
149
- #if NET
150
97
[ SupportedOSPlatform ( "ios" ) ]
151
98
[ SupportedOSPlatform ( "macos" ) ]
152
99
[ SupportedOSPlatform ( "maccatalyst" ) ]
153
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
154
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
155
- #else
156
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
157
- #endif
100
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
101
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
102
+ // Not deprecated on macOS
158
103
[ DllImport ( Constants . SystemConfigurationLibrary ) ]
159
104
extern static byte CNMarkPortalOnline ( IntPtr /* CFStringRef __nonnull */ interfaceName ) ;
160
105
161
- #if NET
162
- /// <param name="iface">To be added.</param>
163
- /// <summary>To be added.</summary>
164
- /// <returns>To be added.</returns>
165
- /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
106
+ /// <summary>Let the system know that the specified interface has now been authenticated and is now a viable network interface for the rest of the system.</summary>
107
+ /// <param name="iface">The network interface that is now authenticated.</param>
108
+ /// <returns>A boolean value indicating whether the operation was successful or not.</returns>
109
+ /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
166
110
[ SupportedOSPlatform ( "ios" ) ]
167
111
[ SupportedOSPlatform ( "macos" ) ]
168
112
[ SupportedOSPlatform ( "maccatalyst" ) ]
169
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
170
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
171
- #else
172
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
173
- #endif
113
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
114
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
115
+ // Not deprecated on macOS
174
116
static public bool MarkPortalOnline ( string iface )
175
117
{
176
- using ( var nss = new NSString ( iface ) ) {
177
- bool result = CNMarkPortalOnline ( nss . Handle ) != 0 ;
178
- GC . KeepAlive ( nss ) ;
179
- return result ;
180
- }
118
+ if ( string . IsNullOrEmpty ( iface ) )
119
+ ThrowHelper . ThrowArgumentNullException ( nameof ( iface ) ) ;
120
+
121
+ using var nss = new TransientCFString ( iface ) ;
122
+ return CNMarkPortalOnline ( nss ) != 0 ;
181
123
}
182
124
183
- #if NET
184
- /// <param name="iface">To be added.</param>
185
- /// <summary>To be added.</summary>
186
- /// <returns>To be added.</returns>
187
- /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
125
+ /// <summary>Let the system know that the specified interface has not authenticated and is not a viable network interface for the rest of the system.</summary>
126
+ /// <param name="iface">The network interface that is not authenticated.</param>
127
+ /// <returns>A boolean value indicating whether the operation was successful or not.</returns>
128
+ /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
188
129
[ SupportedOSPlatform ( "ios" ) ]
189
130
[ SupportedOSPlatform ( "macos" ) ]
190
131
[ SupportedOSPlatform ( "maccatalyst" ) ]
191
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
192
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
193
- #else
194
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
195
- #endif
132
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
133
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
134
+ // Not deprecated on macOS
196
135
static public bool MarkPortalOffline ( string iface )
197
136
{
198
- using ( var nss = new NSString ( iface ) ) {
199
- bool result = CNMarkPortalOffline ( nss . Handle ) != 0 ;
200
- GC . KeepAlive ( nss ) ;
201
- return result ;
202
- }
137
+ if ( string . IsNullOrEmpty ( iface ) )
138
+ ThrowHelper . ThrowArgumentNullException ( nameof ( iface ) ) ;
139
+
140
+ using var nss = new TransientCFString ( iface ) ;
141
+ return CNMarkPortalOffline ( nss ) != 0 ;
203
142
}
204
143
205
- #if NET
206
144
[ SupportedOSPlatform ( "ios" ) ]
207
145
[ SupportedOSPlatform ( "macos" ) ]
208
146
[ SupportedOSPlatform ( "maccatalyst" ) ]
209
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
210
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
211
- #else
212
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
213
- #endif
147
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
148
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
149
+ // Not deprecated on macOS
214
150
[ DllImport ( Constants . SystemConfigurationLibrary ) ]
215
151
extern static byte CNSetSupportedSSIDs ( IntPtr /* CFArrayRef __nonnull */ ssidArray ) ;
216
152
217
- #if NET
218
- /// <param name="ssids">To be added.</param>
219
- /// <summary>To be added.</summary>
220
- /// <returns>To be added.</returns>
221
- /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
153
+ /// <summary>Set an array of SSIDs the application will authenticate.</summary>
154
+ /// <param name="ssids">The array of SSIDs the application will authenticate.</param>
155
+ /// <returns>A boolean value indicating whether the operation was successful or not.</returns>
156
+ /// <remarks>This API is only available on devices. An EntryPointNotFoundException will be thrown on the simulator</remarks>
222
157
[ SupportedOSPlatform ( "ios" ) ]
223
158
[ SupportedOSPlatform ( "macos" ) ]
224
159
[ SupportedOSPlatform ( "maccatalyst" ) ]
225
- [ ObsoletedOSPlatform ( "maccatalyst13.1" ) ]
226
- [ ObsoletedOSPlatform ( "ios9.0" ) ]
227
- #else
228
- [ Deprecated ( PlatformName . iOS , 9 , 0 ) ]
229
- #endif
160
+ [ ObsoletedOSPlatform ( "ios" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
161
+ [ ObsoletedOSPlatform ( "maccatalyst" , "Use 'NetworkExtension.NEHotspotHelper' instead." ) ]
162
+ // Not deprecated on macOS
230
163
static public bool SetSupportedSSIDs ( string [ ] ssids )
231
164
{
232
- using ( var arr = NSArray . FromStrings ( ssids ) ) {
233
- bool result = CNSetSupportedSSIDs ( arr . Handle ) != 0 ;
234
- GC . KeepAlive ( arr ) ;
235
- return result ;
236
- }
165
+ using var arr = NSArray . FromStrings ( ssids ) ;
166
+ return CNSetSupportedSSIDs ( arr . Handle ) != 0 ;
237
167
}
238
168
#endif // __TVOS__
239
169
}
0 commit comments