Update 'Reachability' sample (#331)
* added new sample * updated labels * deleted old sample * added assets * updated readme and screenshots * updated screenshot's size * updated root folder name
|
@ -0,0 +1,27 @@
|
|||
Reachability Sample
|
||||
===================
|
||||
|
||||
The Reachability sample application demonstrates how to use the System Configuration framework to monitor the network state of an iOS device. In particular, it demonstrates how to know when IP can be routed and when traffic will be routed through a Wireless Wide Area Network (WWAN) interface such as EDGE or 3G.
|
||||
|
||||
Note: Reachability cannot tell your application if you can connect to a particular host, only that an interface is available that might allow a connection, and whether that interface is the WWAN. To understand when and how to use Reachability, read [Networking Overview][1].
|
||||
|
||||
[1]: <http://developer.apple.com/library/ios/#documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/>
|
||||
|
||||
![iPhone running Reachability sample](Screenshots/screenshot-1.png)
|
||||
|
||||
|
||||
Related Links
|
||||
-------
|
||||
|
||||
- [Original sample](https://developer.apple.com/library/archive/samplecode/Reachability/Introduction/Intro.html).
|
||||
- [Documentation](http://developer.apple.com/library/ios/#documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/)
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Xamarin port changes are released under the MIT license.
|
||||
|
||||
Author
|
||||
-------
|
||||
|
||||
Miguel de Icaza
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reachability", "Reachability.csproj", "{E1356D0A-1572-4157-BD97-05F0B9DA832E}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reachability", "Reachability\Reachability.csproj", "{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -11,13 +11,13 @@ Global
|
|||
Release|iPhone = Release|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{E1356D0A-1572-4157-BD97-05F0B9DA832E}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}.Release|iPhone.Build.0 = Release|iPhone
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,21 @@
|
|||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
// The UIApplicationDelegate for the application. This class is responsible for launching the
|
||||
// User Interface of the application, as well as listening (and optionally responding) to application events from iOS.
|
||||
[Register("AppDelegate")]
|
||||
public class AppDelegate : UIApplicationDelegate
|
||||
{
|
||||
public override UIWindow Window { get; set; }
|
||||
|
||||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
|
||||
{
|
||||
// Override point for customization after application launch.
|
||||
// If not required for your application you can safely delete this method
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
{
|
||||
"images": [
|
||||
{
|
||||
"size": "20x20",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "20x20",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-29@2x.png",
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-29@3x.png",
|
||||
"size": "29x29",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-40@2x.png",
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-40@3x.png",
|
||||
"size": "40x40",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "icon-app-60@2x.png",
|
||||
"size": "60x60",
|
||||
"scale": "2x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"filename": "Icon-app-60@3x.png",
|
||||
"size": "60x60",
|
||||
"scale": "3x",
|
||||
"idiom": "iphone"
|
||||
},
|
||||
{
|
||||
"size": "20x20",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "20x20",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-29.png",
|
||||
"size": "29x29",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-29@2x.png",
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "icon-spotlight-40@2x.png",
|
||||
"size": "40x40",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "Icon-app-83.5@2x.png",
|
||||
"size": "83.5x83.5",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "icon-app-76.png",
|
||||
"size": "76x76",
|
||||
"scale": "1x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "icon-app-76@2x.png",
|
||||
"size": "76x76",
|
||||
"scale": "2x",
|
||||
"idiom": "ipad"
|
||||
},
|
||||
{
|
||||
"filename": "app-store-logo.png",
|
||||
"size": "1024x1024",
|
||||
"scale": "1x",
|
||||
"idiom": "ios-marketing"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "2x",
|
||||
"idiom": "car"
|
||||
},
|
||||
{
|
||||
"size": "60x60",
|
||||
"scale": "3x",
|
||||
"idiom": "car"
|
||||
},
|
||||
{
|
||||
"role": "notificationCenter",
|
||||
"size": "24x24",
|
||||
"subtype": "38mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "notificationCenter",
|
||||
"size": "27.5x27.5",
|
||||
"subtype": "42mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "companionSettings",
|
||||
"size": "29x29",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "companionSettings",
|
||||
"size": "29x29",
|
||||
"scale": "3x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "appLauncher",
|
||||
"size": "40x40",
|
||||
"subtype": "38mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "appLauncher",
|
||||
"size": "44x44",
|
||||
"subtype": "40mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "appLauncher",
|
||||
"size": "50x50",
|
||||
"subtype": "44mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "quickLook",
|
||||
"size": "86x86",
|
||||
"subtype": "38mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "quickLook",
|
||||
"size": "98x98",
|
||||
"subtype": "42mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"role": "quickLook",
|
||||
"size": "108x108",
|
||||
"subtype": "44mm",
|
||||
"scale": "2x",
|
||||
"idiom": "watch"
|
||||
},
|
||||
{
|
||||
"size": "1024x1024",
|
||||
"scale": "1x",
|
||||
"idiom": "watch-marketing"
|
||||
},
|
||||
{
|
||||
"size": "16x16",
|
||||
"scale": "1x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "16x16",
|
||||
"scale": "2x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "32x32",
|
||||
"scale": "1x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "32x32",
|
||||
"scale": "2x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "128x128",
|
||||
"scale": "1x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "128x128",
|
||||
"scale": "2x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "256x256",
|
||||
"scale": "1x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "256x256",
|
||||
"scale": "2x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "512x512",
|
||||
"scale": "1x",
|
||||
"idiom": "mac"
|
||||
},
|
||||
{
|
||||
"size": "512x512",
|
||||
"scale": "2x",
|
||||
"idiom": "mac"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"version": 1,
|
||||
"author": "xcode"
|
||||
}
|
||||
}
|
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/Icon-app-60@3x.png
Normal file
После Ширина: | Высота: | Размер: 5.0 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/Icon-app-83.5@2x.png
Normal file
После Ширина: | Высота: | Размер: 8.6 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/app-store-logo.png
Normal file
После Ширина: | Высота: | Размер: 22 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-app-60@2x.png
Normal file
После Ширина: | Высота: | Размер: 3.3 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-app-76.png
Normal file
После Ширина: | Высота: | Размер: 2.0 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-app-76@2x.png
Normal file
После Ширина: | Высота: | Размер: 4.3 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-spotlight-29.png
Normal file
После Ширина: | Высота: | Размер: 900 B |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-spotlight-29@2x.png
Normal file
После Ширина: | Высота: | Размер: 1.8 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-spotlight-29@3x.png
Normal file
После Ширина: | Высота: | Размер: 2.5 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-spotlight-40@2x.png
Normal file
После Ширина: | Высота: | Размер: 2.2 KiB |
Двоичные данные
Reachability/Reachability/Assets.xcassets/AppIcon.appiconset/icon-spotlight-40@3x.png
Normal file
После Ширина: | Высота: | Размер: 3.3 KiB |
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?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>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,39 @@
|
|||
<?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>CFBundleName</key>
|
||||
<string>Reachability</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.xamarin.reachability</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>9.0</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Assets.xcassets/AppIcon.appiconset</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Xamarin" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tvm-6m-sqO">
|
||||
<rect key="frame" x="116.5" y="319.5" width="142" height="48"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="40"/>
|
||||
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="tvm-6m-sqO" firstAttribute="centerY" secondItem="T2q-67-rvl" secondAttribute="centerY" id="9KR-gO-36Y"/>
|
||||
<constraint firstItem="tvm-6m-sqO" firstAttribute="centerX" secondItem="T2q-67-rvl" secondAttribute="centerX" id="G2I-bB-iT2"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="T2q-67-rvl"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
|
@ -0,0 +1,15 @@
|
|||
using UIKit;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
// This is the main entry point of the application.
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main(args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ohb-Sr-0wi">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Reachability-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Remote Host:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ocQ-dW-Keh">
|
||||
<rect key="frame" x="16" y="78" width="104" height="20.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="xsO-6A-CzT">
|
||||
<rect key="frame" x="16" y="106.5" width="30" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="2eo-ZN-9Kh"/>
|
||||
<constraint firstAttribute="width" constant="30" id="TAb-fY-6Vx"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" clearsOnBeginEditing="YES" minimumFontSize="12" translatesAutoresizingMaskIntoConstraints="NO" id="KxN-0d-SZx">
|
||||
<rect key="frame" x="54" y="106.5" width="305" height="30"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="12"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TCP/IP Routing Available" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CVU-jC-KYe">
|
||||
<rect key="frame" x="16" y="144.5" width="186" height="20.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="tMb-N7-Au6">
|
||||
<rect key="frame" x="16" y="173" width="30" height="30"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="30" id="5rP-g0-hYo"/>
|
||||
<constraint firstAttribute="width" constant="30" id="RSa-6d-EQt"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" clearsOnBeginEditing="YES" minimumFontSize="12" translatesAutoresizingMaskIntoConstraints="NO" id="Tc0-En-72U">
|
||||
<rect key="frame" x="54" y="173" width="305" height="30"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="12"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XTh-Ol-sG6">
|
||||
<rect key="frame" x="16" y="211" width="343" height="41"/>
|
||||
<string key="text">Cellular data network is available.
|
||||
Internet traffic will be routed through it.</string>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="1te-Fb-293" firstAttribute="trailing" secondItem="KxN-0d-SZx" secondAttribute="trailing" constant="16" id="2GB-mv-NUB"/>
|
||||
<constraint firstItem="CVU-jC-KYe" firstAttribute="top" secondItem="xsO-6A-CzT" secondAttribute="bottom" constant="8" id="3GZ-ha-AEf"/>
|
||||
<constraint firstItem="KxN-0d-SZx" firstAttribute="centerY" secondItem="xsO-6A-CzT" secondAttribute="centerY" id="6L2-P9-5gV"/>
|
||||
<constraint firstItem="tMb-N7-Au6" firstAttribute="leading" secondItem="1te-Fb-293" secondAttribute="leading" constant="16" id="Ajg-1o-GCq"/>
|
||||
<constraint firstItem="Tc0-En-72U" firstAttribute="centerY" secondItem="tMb-N7-Au6" secondAttribute="centerY" id="FfT-dn-Mi3"/>
|
||||
<constraint firstItem="XTh-Ol-sG6" firstAttribute="leading" secondItem="1te-Fb-293" secondAttribute="leading" constant="16" id="Kqs-wR-N6g"/>
|
||||
<constraint firstItem="ocQ-dW-Keh" firstAttribute="top" secondItem="1te-Fb-293" secondAttribute="top" constant="8" id="LUn-RJ-mbU"/>
|
||||
<constraint firstItem="CVU-jC-KYe" firstAttribute="leading" secondItem="1te-Fb-293" secondAttribute="leading" constant="16" id="VcE-ts-HuR"/>
|
||||
<constraint firstItem="1te-Fb-293" firstAttribute="trailing" secondItem="XTh-Ol-sG6" secondAttribute="trailing" constant="16" id="bRj-tI-aMd"/>
|
||||
<constraint firstItem="xsO-6A-CzT" firstAttribute="leading" secondItem="1te-Fb-293" secondAttribute="leading" constant="16" id="muj-YF-ywa"/>
|
||||
<constraint firstItem="xsO-6A-CzT" firstAttribute="top" secondItem="ocQ-dW-Keh" secondAttribute="bottom" constant="8" id="nIf-qP-yrO"/>
|
||||
<constraint firstItem="1te-Fb-293" firstAttribute="trailing" secondItem="Tc0-En-72U" secondAttribute="trailing" constant="16" id="o77-bG-oqF"/>
|
||||
<constraint firstItem="KxN-0d-SZx" firstAttribute="leading" secondItem="xsO-6A-CzT" secondAttribute="trailing" constant="8" id="qf2-qX-Xy8"/>
|
||||
<constraint firstItem="Tc0-En-72U" firstAttribute="leading" secondItem="tMb-N7-Au6" secondAttribute="trailing" constant="8" id="uWe-ef-Za6"/>
|
||||
<constraint firstItem="XTh-Ol-sG6" firstAttribute="top" secondItem="tMb-N7-Au6" secondAttribute="bottom" constant="8" id="wXw-S0-vhA"/>
|
||||
<constraint firstItem="ocQ-dW-Keh" firstAttribute="leading" secondItem="1te-Fb-293" secondAttribute="leading" constant="16" id="xbQ-Gf-cN4"/>
|
||||
<constraint firstItem="tMb-N7-Au6" firstAttribute="top" secondItem="CVU-jC-KYe" secondAttribute="bottom" constant="8" id="yb4-s7-hhq"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="1te-Fb-293"/>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" title="Reachability" id="ncb-hI-JF9"/>
|
||||
<connections>
|
||||
<outlet property="summaryLabel" destination="XTh-Ol-sG6" id="name-outlet-XTh-Ol-sG6"/>
|
||||
<outlet property="internetConnectionImageView" destination="tMb-N7-Au6" id="name-outlet-tMb-N7-Au6"/>
|
||||
<outlet property="internetConnectionStatusField" destination="Tc0-En-72U" id="name-outlet-Tc0-En-72U"/>
|
||||
<outlet property="remoteHostStatusField" destination="KxN-0d-SZx" id="name-outlet-KxN-0d-SZx"/>
|
||||
<outlet property="remoteHostImageView" destination="xsO-6A-CzT" id="name-outlet-xsO-6A-CzT"/>
|
||||
<outlet property="remoteHostLabel" destination="ocQ-dW-Keh" id="name-outlet-ocQ-dW-Keh"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1072.8" y="133.5832"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="pgG-yf-juV">
|
||||
<objects>
|
||||
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="Ohb-Sr-0wi" sceneMemberID="viewController">
|
||||
<toolbarItems/>
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="KhK-wb-wcf">
|
||||
<rect key="frame" x="0.0" y="20" width="375" height="50"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<nil name="viewControllers"/>
|
||||
<connections>
|
||||
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="y7h-3l-S5f"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="kO0-2M-1Di" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="177" y="134"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
|
@ -0,0 +1,154 @@
|
|||
using CoreFoundation;
|
||||
using Foundation;
|
||||
using SystemConfiguration;
|
||||
using System.Net;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
public enum NetworkStatus
|
||||
{
|
||||
NotReachable,
|
||||
ReachableViaWWAN,
|
||||
ReachableViaWiFi
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
|
||||
/// </summary>
|
||||
public class Reachability : NSObject
|
||||
{
|
||||
~Reachability()
|
||||
{
|
||||
StopNotifier();
|
||||
if (NetworkReachability != null)
|
||||
{
|
||||
NetworkReachability.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReachabilityChangedNotification { get; } = "kNetworkReachabilityChangedNotification";
|
||||
|
||||
public NetworkReachability NetworkReachability { get; private set; }
|
||||
|
||||
public static Reachability ReachabilityWithHostName(string hostName)
|
||||
{
|
||||
var reachability = new NetworkReachability(hostName);
|
||||
return new Reachability { NetworkReachability = reachability };
|
||||
}
|
||||
|
||||
public static Reachability ReachabilityWithAddress(IPAddress hostAddress)
|
||||
{
|
||||
var reachability = new NetworkReachability(hostAddress);
|
||||
return new Reachability { NetworkReachability = reachability };
|
||||
}
|
||||
|
||||
public static Reachability ReachabilityForInternetConnection()
|
||||
{
|
||||
var reachability = new NetworkReachability(new IPAddress(0));
|
||||
return new Reachability { NetworkReachability = reachability };
|
||||
}
|
||||
|
||||
private void HandleNotification(NetworkReachabilityFlags flags)
|
||||
{
|
||||
// Post a notification to notify the client that the network reachability changed.
|
||||
NSNotificationCenter.DefaultCenter.PostNotificationName(ReachabilityChangedNotification, this);
|
||||
}
|
||||
|
||||
#region Start and stop notifier
|
||||
|
||||
public bool StartNotifier()
|
||||
{
|
||||
var result = false;
|
||||
|
||||
var status = NetworkReachability.SetNotification(HandleNotification);
|
||||
if (status == StatusCode.OK)
|
||||
{
|
||||
result = NetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void StopNotifier()
|
||||
{
|
||||
if (NetworkReachability != null)
|
||||
{
|
||||
NetworkReachability.Unschedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Network Flag Handling
|
||||
|
||||
public NetworkStatus NetworkStatusForFlags(NetworkReachabilityFlags flags)
|
||||
{
|
||||
if ((flags & NetworkReachabilityFlags.Reachable) == 0)
|
||||
{
|
||||
// The target host is not reachable.
|
||||
return NetworkStatus.NotReachable;
|
||||
}
|
||||
|
||||
NetworkStatus result = NetworkStatus.NotReachable;
|
||||
if ((flags & NetworkReachabilityFlags.ConnectionRequired) == 0)
|
||||
{
|
||||
// If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
|
||||
result = NetworkStatus.ReachableViaWiFi;
|
||||
}
|
||||
|
||||
if ((flags & NetworkReachabilityFlags.ConnectionOnDemand) != 0 ||
|
||||
(flags & NetworkReachabilityFlags.ConnectionOnTraffic) != 0)
|
||||
{
|
||||
// ... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs...
|
||||
if ((flags & NetworkReachabilityFlags.InterventionRequired) == 0)
|
||||
{
|
||||
// ... and no [user] intervention is needed...
|
||||
result = NetworkStatus.ReachableViaWiFi;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & NetworkReachabilityFlags.IsWWAN) == NetworkReachabilityFlags.IsWWAN)
|
||||
{
|
||||
// ... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
|
||||
result = NetworkStatus.ReachableViaWWAN;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool ConnectionRequired()
|
||||
{
|
||||
if (NetworkReachability.TryGetFlags(out NetworkReachabilityFlags flags))
|
||||
{
|
||||
return (flags & NetworkReachabilityFlags.ConnectionRequired) != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public NetworkStatus CurrentReachabilityStatus()
|
||||
{
|
||||
var returnValue = NetworkStatus.NotReachable;
|
||||
if (NetworkReachability.TryGetFlags(out NetworkReachabilityFlags flags))
|
||||
{
|
||||
returnValue = this.NetworkStatusForFlags(flags);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
{
|
||||
if (NetworkReachability != null)
|
||||
{
|
||||
NetworkReachability.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{E38A885A-4DD2-4A1F-8A8F-FCAC3001957F}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Reachability</RootNamespace>
|
||||
<AssemblyName>Reachability</AssemblyName>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<IOSDebuggerPort>57406</IOSDebuggerPort>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
<DeviceSpecificBuild>false</DeviceSpecificBuild>
|
||||
<MtouchVerbosity></MtouchVerbosity>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchUseLlvm>true</MtouchUseLlvm>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
<MtouchVerbosity></MtouchVerbosity>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<DefineConstants></DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
<MtouchVerbosity></MtouchVerbosity>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<IOSDebuggerPort>50945</IOSDebuggerPort>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
<MtouchVerbosity></MtouchVerbosity>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
|
||||
<ImageAsset Include="Assets.xcassets\Contents.json" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\app-store-logo.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Icon-app-83.5%402x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-app-76%402x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-app-76.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-spotlight-29.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-spotlight-29%402x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-app-60%402x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Icon-app-60%403x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-spotlight-40%402x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-spotlight-40%403x.png" />
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\icon-spotlight-29%403x.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="LaunchScreen.storyboard" />
|
||||
<InterfaceDefinition Include="Main.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="ViewController.cs" />
|
||||
<Compile Include="ViewController.designer.cs">
|
||||
<DependentUpon>ViewController.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Reachability.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\Airport.png" />
|
||||
<BundleResource Include="Resources\stop-32.png" />
|
||||
<BundleResource Include="Resources\WWAN5.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
До Ширина: | Высота: | Размер: 2.0 KiB После Ширина: | Высота: | Размер: 2.0 KiB |
До Ширина: | Высота: | Размер: 1.3 KiB После Ширина: | Высота: | Размер: 1.3 KiB |
До Ширина: | Высота: | Размер: 1.4 KiB После Ширина: | Высота: | Размер: 1.4 KiB |
|
@ -0,0 +1,111 @@
|
|||
using System;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
public partial class ViewController : UIViewController
|
||||
{
|
||||
private Reachability internetReachability;
|
||||
|
||||
private Reachability hostReachability;
|
||||
|
||||
protected ViewController(IntPtr handle) : base(handle) { }
|
||||
|
||||
public override void ViewDidLoad()
|
||||
{
|
||||
base.ViewDidLoad();
|
||||
|
||||
summaryLabel.Hidden = true;
|
||||
|
||||
// Change the host name here to change the server you want to monitor.
|
||||
const string remoteHostName = "www.google.com";
|
||||
remoteHostLabel.Text = $"Remote Host: {remoteHostName}";
|
||||
|
||||
hostReachability = Reachability.ReachabilityWithHostName(remoteHostName);
|
||||
hostReachability.StartNotifier();
|
||||
UpdateInterfaceWithReachability(hostReachability);
|
||||
|
||||
internetReachability = Reachability.ReachabilityForInternetConnection();
|
||||
internetReachability.StartNotifier();
|
||||
UpdateInterfaceWithReachability(internetReachability);
|
||||
}
|
||||
|
||||
public override void ViewDidAppear(bool animated)
|
||||
{
|
||||
base.ViewDidAppear(animated);
|
||||
|
||||
// Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the method reachabilityChanged will be called.
|
||||
NSNotificationCenter.DefaultCenter.AddObserver(new NSString(Reachability.ReachabilityChangedNotification), OnReachabilityChanged);
|
||||
}
|
||||
|
||||
public override void ViewDidDisappear(bool animated)
|
||||
{
|
||||
base.ViewDidDisappear(animated);
|
||||
NSNotificationCenter.DefaultCenter.RemoveObserver(this, Reachability.ReachabilityChangedNotification);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by Reachability whenever status changes.
|
||||
/// </summary>
|
||||
/// <param name="notification">Object.</param>
|
||||
private void OnReachabilityChanged(NSNotification notification)
|
||||
{
|
||||
var reachability = notification.Object as Reachability;
|
||||
UpdateInterfaceWithReachability(reachability);
|
||||
}
|
||||
|
||||
private void UpdateInterfaceWithReachability(Reachability reachability)
|
||||
{
|
||||
if (reachability == hostReachability)
|
||||
{
|
||||
ConfigureTextField(remoteHostStatusField, remoteHostImageView, reachability);
|
||||
|
||||
var networkStatus = reachability.CurrentReachabilityStatus();
|
||||
var connectionRequired = reachability.ConnectionRequired();
|
||||
var baseLabelText = connectionRequired ? "Cellular data network is available.\nInternet traffic will be routed through it after a connection is established."
|
||||
: "Cellular data network is active.\nInternet traffic will be routed through it.";
|
||||
summaryLabel.Text = baseLabelText;
|
||||
summaryLabel.Hidden = networkStatus != NetworkStatus.ReachableViaWWAN;
|
||||
}
|
||||
else if (reachability == internetReachability)
|
||||
{
|
||||
ConfigureTextField(internetConnectionStatusField, internetConnectionImageView, reachability);
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureTextField(UITextField textField, UIImageView imageView, Reachability reachability)
|
||||
{
|
||||
var networkStatus = reachability.CurrentReachabilityStatus();
|
||||
var connectionRequired = reachability.ConnectionRequired();
|
||||
var statusString = string.Empty;
|
||||
|
||||
switch (networkStatus)
|
||||
{
|
||||
case NetworkStatus.NotReachable:
|
||||
statusString = "Access Not Available";
|
||||
imageView.Image = UIImage.FromBundle("stop-32.png");
|
||||
// Minor interface detail - connectionRequired may return YES even when the host is unreachable. We cover that up here...
|
||||
connectionRequired = false;
|
||||
break;
|
||||
|
||||
case NetworkStatus.ReachableViaWWAN:
|
||||
statusString = "Reachable WWAN";
|
||||
imageView.Image = UIImage.FromBundle("WWAN5.png");
|
||||
break;
|
||||
|
||||
case NetworkStatus.ReachableViaWiFi:
|
||||
statusString = "Reachable WiFi";
|
||||
imageView.Image = UIImage.FromBundle("Airport.png");
|
||||
break;
|
||||
}
|
||||
|
||||
if (connectionRequired)
|
||||
{
|
||||
statusString = $"{statusString}, Connection Required";
|
||||
}
|
||||
|
||||
textField.Text = statusString;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// WARNING
|
||||
//
|
||||
// This file has been generated automatically by Visual Studio from the outlets and
|
||||
// actions declared in your storyboard file.
|
||||
// Manual changes to this file will not be maintained.
|
||||
//
|
||||
using Foundation;
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
[Register ("ViewController")]
|
||||
partial class ViewController
|
||||
{
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UIImageView internetConnectionImageView { get; set; }
|
||||
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UITextField internetConnectionStatusField { get; set; }
|
||||
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UIImageView remoteHostImageView { get; set; }
|
||||
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UILabel remoteHostLabel { get; set; }
|
||||
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UITextField remoteHostStatusField { get; set; }
|
||||
|
||||
[Outlet]
|
||||
[GeneratedCode ("iOS Designer", "1.0")]
|
||||
UIKit.UILabel summaryLabel { get; set; }
|
||||
|
||||
void ReleaseDesignerOutlets ()
|
||||
{
|
||||
if (internetConnectionImageView != null) {
|
||||
internetConnectionImageView.Dispose ();
|
||||
internetConnectionImageView = null;
|
||||
}
|
||||
|
||||
if (internetConnectionStatusField != null) {
|
||||
internetConnectionStatusField.Dispose ();
|
||||
internetConnectionStatusField = null;
|
||||
}
|
||||
|
||||
if (remoteHostImageView != null) {
|
||||
remoteHostImageView.Dispose ();
|
||||
remoteHostImageView = null;
|
||||
}
|
||||
|
||||
if (remoteHostLabel != null) {
|
||||
remoteHostLabel.Dispose ();
|
||||
remoteHostLabel = null;
|
||||
}
|
||||
|
||||
if (remoteHostStatusField != null) {
|
||||
remoteHostStatusField.Dispose ();
|
||||
remoteHostStatusField = null;
|
||||
}
|
||||
|
||||
if (summaryLabel != null) {
|
||||
summaryLabel.Dispose ();
|
||||
summaryLabel = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
После Ширина: | Высота: | Размер: 31 KiB |
|
@ -1,10 +0,0 @@
|
|||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Reachability {
|
||||
[Register ("AppDelegate")]
|
||||
public class AppDelegate : UIApplicationDelegate {
|
||||
public override UIWindow Window { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?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>CFBundleIconFiles</key>
|
||||
<array>
|
||||
<string>Resources/icon-57.png</string>
|
||||
<string>Resources/icon-114.png</string>
|
||||
<string>Resources/icon-72.png</string>
|
||||
<string>Resources/icon-144.png</string>
|
||||
<string>Resources/icon-29.png</string>
|
||||
<string>Resources/icon-58.png</string>
|
||||
<string>Resources/icon-50.png</string>
|
||||
<string>Resources/icon-100.png</string>
|
||||
</array>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainWindow</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Reachability</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.xamarin.Reachability</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
</array>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>9.0</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -1,14 +0,0 @@
|
|||
using UIKit;
|
||||
|
||||
namespace Reachability {
|
||||
public class Application {
|
||||
// This is the main entry point of the application.
|
||||
static void Main (string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main (args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8187.4" systemVersion="15A178w" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="G6t-Sy-zaY">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8151.3"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Root View Controller-->
|
||||
<scene sceneID="AaP-65-3tI">
|
||||
<objects>
|
||||
<tableViewController id="uYg-Wb-NE8" customClass="MainViewController" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="bpy-jb-hsL">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="V1L-rk-bW7">
|
||||
<rect key="frame" x="0.0" y="92" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="V1L-rk-bW7" id="mEc-0D-cmu">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</tableViewCellContentView>
|
||||
<animations/>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="uYg-Wb-NE8" id="UW0-nO-B63"/>
|
||||
<outlet property="delegate" destination="uYg-Wb-NE8" id="SFR-fz-wuW"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
<navigationItem key="navigationItem" title="Root View Controller" id="WD6-LY-Wq6"/>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="WLN-0l-dYf" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="748" y="134"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="rk5-AZ-VT1">
|
||||
<objects>
|
||||
<navigationController id="G6t-Sy-zaY" sceneMemberID="viewController">
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" id="AZi-ef-rH6">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</navigationBar>
|
||||
<connections>
|
||||
<segue destination="uYg-Wb-NE8" kind="relationship" relationship="rootViewController" id="FKX-Rz-4BI"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="R6s-Lf-xV5" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="208" y="134"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
|
@ -1,134 +0,0 @@
|
|||
using System;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Reachability {
|
||||
public partial class MainViewController : UITableViewController {
|
||||
const string ReachabilityTableCellIdentifier = "ReachabilityTableCell";
|
||||
|
||||
UIImage imageCarrier, imageWiFi, imageStop;
|
||||
NetworkStatus remoteHostStatus, internetStatus, localWifiStatus;
|
||||
|
||||
public MainViewController (IntPtr handle) : base (handle)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ViewDidLoad ()
|
||||
{
|
||||
base.ViewDidLoad ();
|
||||
UpdateStatus (null, null);
|
||||
Reachability.ReachabilityChanged += UpdateStatus;
|
||||
|
||||
imageCarrier = UIImage.FromFile ("WWAN5.png");
|
||||
imageWiFi = UIImage.FromFile ("Airport.png");
|
||||
imageStop = UIImage.FromFile ("stop-32.png");
|
||||
|
||||
TableView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
|
||||
TableView.RowHeight = 44f;
|
||||
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
|
||||
TableView.SectionHeaderHeight = 28f;
|
||||
TableView.ScrollEnabled = false;
|
||||
}
|
||||
|
||||
public override NSIndexPath WillSelectRow (UITableView tableView, NSIndexPath indexPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override nint RowsInSection (UITableView tableView, nint section)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override nint NumberOfSections (UITableView tableView)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public override string TitleForHeader (UITableView tableView, nint section)
|
||||
{
|
||||
switch (section) {
|
||||
case 0:
|
||||
return Reachability.HostName;
|
||||
case 1:
|
||||
return "Access to internet hosts";
|
||||
case 2:
|
||||
return "Access to Local Bonjour Hosts";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
|
||||
{
|
||||
var cell = tableView.DequeueReusableCell (ReachabilityTableCellIdentifier);
|
||||
if (cell == null) {
|
||||
cell = new UITableViewCell (UITableViewCellStyle.Default, ReachabilityTableCellIdentifier);
|
||||
var label = cell.TextLabel;
|
||||
label.Font = UIFont.SystemFontOfSize (12f);
|
||||
label.TextColor = UIColor.DarkGray;
|
||||
label.TextAlignment = UITextAlignment.Left;
|
||||
}
|
||||
|
||||
string text = string.Empty;
|
||||
UIImage image = null;
|
||||
switch (indexPath.Section) {
|
||||
case 0:
|
||||
switch (remoteHostStatus) {
|
||||
case NetworkStatus.NotReachable:
|
||||
text = "Cannot connect to remote host";
|
||||
image = imageStop;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaCarrierDataNetwork:
|
||||
text = "Reachable via data carrier network";
|
||||
image = imageCarrier;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaWiFiNetwork:
|
||||
text = "Reachable via WiFi network";
|
||||
image = imageWiFi;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
switch (internetStatus) {
|
||||
case NetworkStatus.NotReachable:
|
||||
text = "Access not available";
|
||||
image = imageStop;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaCarrierDataNetwork:
|
||||
text = "Available via data carrier network";
|
||||
image = imageCarrier;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaWiFiNetwork:
|
||||
text = "Available via WiFi network";
|
||||
image = imageWiFi;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (localWifiStatus) {
|
||||
case NetworkStatus.NotReachable:
|
||||
text = "Access not available";
|
||||
image = imageStop;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaWiFiNetwork:
|
||||
text = "Available via WiFi network";
|
||||
image = imageWiFi;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cell.TextLabel.Text = text;
|
||||
cell.ImageView.Image = image;
|
||||
return cell;
|
||||
}
|
||||
|
||||
void UpdateStatus (object sender, EventArgs e)
|
||||
{
|
||||
remoteHostStatus = Reachability.RemoteHostStatus ();
|
||||
internetStatus = Reachability.InternetConnectionStatus ();
|
||||
localWifiStatus = Reachability.LocalWifiConnectionStatus ();
|
||||
TableView.ReloadData ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// WARNING
|
||||
//
|
||||
// This file has been generated automatically by Xamarin Studio to store outlets and
|
||||
// actions made in the UI designer. If it is removed, they will be lost.
|
||||
// Manual changes to this file may not be handled correctly.
|
||||
//
|
||||
using Foundation;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace Reachability
|
||||
{
|
||||
[Register ("MainViewController")]
|
||||
partial class MainViewController
|
||||
{
|
||||
|
||||
void ReleaseDesignerOutlets ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Двоичные данные
ReachabilitySample/Network.png
До Ширина: | Высота: | Размер: 2.1 KiB |
|
@ -1,20 +0,0 @@
|
|||
Reachability Sample
|
||||
===================
|
||||
|
||||
This sample shows how to use the APIs to find out what kind of connectivity is available.
|
||||
|
||||
This sample started as a line-by-line port of the Apple sample, and it
|
||||
was too late when I realize that the sample was not very good to begin
|
||||
with. I have moved on to work on other things, but take this sample
|
||||
(and the Apple one) with a grain of salt, it does not use the best
|
||||
practices nor is it a great use of the APIs in the first place.
|
||||
|
||||
Preview
|
||||
-------
|
||||
|
||||
![iPhone running Reachability sample](http://farm7.static.flickr.com/6127/6002809074_b117d7582e.jpg)
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
Miguel de Icaza
|
|
@ -1,115 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{E1356D0A-1572-4157-BD97-05F0B9DA832E}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>reachability</RootNamespace>
|
||||
<AssemblyName>reachability</AssemblyName>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchI18n></MtouchI18n>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<MtouchArch>x86_64</MtouchArch>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<MtouchArch>ARM64</MtouchArch>
|
||||
<IpaPackageName></IpaPackageName>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<MtouchArch>ARM64</MtouchArch>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="MainViewController.cs" />
|
||||
<Compile Include="MainViewController.designer.cs">
|
||||
<DependentUpon>MainViewController.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Reachability.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="Main.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Network.png" />
|
||||
<Content Include="Airport.png" />
|
||||
<Content Include="stop-32.png" />
|
||||
<Content Include="WWAN5.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BundleResource Include="Resources\Default-568h%402x.png" />
|
||||
<BundleResource Include="Resources\Default-Landscape%402x~ipad.png" />
|
||||
<BundleResource Include="Resources\Default-Landscape~ipad.png" />
|
||||
<BundleResource Include="Resources\Default-Portrait%402x~ipad.png" />
|
||||
<BundleResource Include="Resources\Default-Portrait~ipad.png" />
|
||||
<BundleResource Include="Resources\Default.png" />
|
||||
<BundleResource Include="Resources\Default%402x.png" />
|
||||
<BundleResource Include="Resources\iTunesArtwork%402x.png" />
|
||||
<BundleResource Include="Resources\icon-100.png" />
|
||||
<BundleResource Include="Resources\icon-114.png" />
|
||||
<BundleResource Include="Resources\icon-144.png" />
|
||||
<BundleResource Include="Resources\icon-29.png" />
|
||||
<BundleResource Include="Resources\icon-50.png" />
|
||||
<BundleResource Include="Resources\icon-57.png" />
|
||||
<BundleResource Include="Resources\icon-58.png" />
|
||||
<BundleResource Include="Resources\icon-72.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ITunesArtwork Include="Resources\iTunesArtwork.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
Двоичные данные
ReachabilitySample/Resources/Default-568h@2x.png
До Ширина: | Высота: | Размер: 12 KiB |
Двоичные данные
ReachabilitySample/Resources/Default-Landscape@2x~ipad.png
До Ширина: | Высота: | Размер: 24 KiB |
Двоичные данные
ReachabilitySample/Resources/Default-Landscape~ipad.png
До Ширина: | Высота: | Размер: 9.4 KiB |
Двоичные данные
ReachabilitySample/Resources/Default-Portrait@2x~ipad.png
До Ширина: | Высота: | Размер: 25 KiB |
Двоичные данные
ReachabilitySample/Resources/Default-Portrait~ipad.png
До Ширина: | Высота: | Размер: 9.8 KiB |
Двоичные данные
ReachabilitySample/Resources/Default.png
До Ширина: | Высота: | Размер: 5.2 KiB |
Двоичные данные
ReachabilitySample/Resources/Default@2x.png
До Ширина: | Высота: | Размер: 12 KiB |
Двоичные данные
ReachabilitySample/Resources/iTunesArtwork.png
До Ширина: | Высота: | Размер: 106 KiB |
Двоичные данные
ReachabilitySample/Resources/iTunesArtwork@2x.png
До Ширина: | Высота: | Размер: 273 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-100.png
До Ширина: | Высота: | Размер: 11 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-114.png
До Ширина: | Высота: | Размер: 14 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-144.png
До Ширина: | Высота: | Размер: 18 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-29.png
До Ширина: | Высота: | Размер: 2.0 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-50.png
До Ширина: | Высота: | Размер: 4.2 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-57.png
До Ширина: | Высота: | Размер: 5.1 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-58.png
До Ширина: | Высота: | Размер: 5.2 KiB |
Двоичные данные
ReachabilitySample/Resources/icon-72.png
До Ширина: | Высота: | Размер: 6.6 KiB |
Двоичные данные
ReachabilitySample/Screenshots/ReachabilitySample.jpg
До Ширина: | Высота: | Размер: 53 KiB |
|
@ -1,145 +0,0 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using SystemConfiguration;
|
||||
|
||||
using CoreFoundation;
|
||||
|
||||
namespace Reachability {
|
||||
public enum NetworkStatus {
|
||||
NotReachable,
|
||||
ReachableViaCarrierDataNetwork,
|
||||
ReachableViaWiFiNetwork
|
||||
}
|
||||
|
||||
public static class Reachability {
|
||||
public static string HostName = "www.google.com";
|
||||
|
||||
public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags)
|
||||
{
|
||||
// Is it reachable with the current network configuration?
|
||||
bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;
|
||||
|
||||
// Do we need a connection to reach it?
|
||||
bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0
|
||||
|| (flags & NetworkReachabilityFlags.IsWWAN) != 0;
|
||||
|
||||
return isReachable && noConnectionRequired;
|
||||
}
|
||||
|
||||
// Is the host reachable with the current network configuration
|
||||
public static bool IsHostReachable (string host)
|
||||
{
|
||||
if (string.IsNullOrEmpty (host))
|
||||
return false;
|
||||
|
||||
using (var r = new NetworkReachability (host)) {
|
||||
NetworkReachabilityFlags flags;
|
||||
|
||||
if (r.TryGetFlags (out flags))
|
||||
return IsReachableWithoutRequiringConnection (flags);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Raised every time there is an interesting reachable event,
|
||||
// we do not even pass the info as to what changed, and
|
||||
// we lump all three status we probe into one
|
||||
//
|
||||
public static event EventHandler ReachabilityChanged;
|
||||
|
||||
static void OnChange (NetworkReachabilityFlags flags)
|
||||
{
|
||||
ReachabilityChanged?.Invoke (null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
//
|
||||
// Returns true if it is possible to reach the AdHoc WiFi network
|
||||
// and optionally provides extra network reachability flags as the
|
||||
// out parameter
|
||||
//
|
||||
static NetworkReachability adHocWiFiNetworkReachability;
|
||||
|
||||
public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags)
|
||||
{
|
||||
if (adHocWiFiNetworkReachability == null) {
|
||||
var ipAddress = new IPAddress (new byte[] { 169, 254, 0, 0 });
|
||||
adHocWiFiNetworkReachability = new NetworkReachability (ipAddress.MapToIPv6 ());
|
||||
adHocWiFiNetworkReachability.SetNotification (OnChange);
|
||||
adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
|
||||
return adHocWiFiNetworkReachability.TryGetFlags (out flags) && IsReachableWithoutRequiringConnection (flags);
|
||||
}
|
||||
|
||||
static NetworkReachability defaultRouteReachability;
|
||||
|
||||
static bool IsNetworkAvailable (out NetworkReachabilityFlags flags)
|
||||
{
|
||||
if (defaultRouteReachability == null) {
|
||||
var ipAddress = new IPAddress (0);
|
||||
defaultRouteReachability = new NetworkReachability (ipAddress.MapToIPv6 ());
|
||||
defaultRouteReachability.SetNotification (OnChange);
|
||||
defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
return defaultRouteReachability.TryGetFlags (out flags) && IsReachableWithoutRequiringConnection (flags);
|
||||
}
|
||||
|
||||
static NetworkReachability remoteHostReachability;
|
||||
|
||||
public static NetworkStatus RemoteHostStatus ()
|
||||
{
|
||||
NetworkReachabilityFlags flags;
|
||||
bool reachable;
|
||||
|
||||
if (remoteHostReachability == null) {
|
||||
remoteHostReachability = new NetworkReachability (HostName);
|
||||
|
||||
// Need to probe before we queue, or we wont get any meaningful values
|
||||
// this only happens when you create NetworkReachability from a hostname
|
||||
reachable = remoteHostReachability.TryGetFlags (out flags);
|
||||
|
||||
remoteHostReachability.SetNotification (OnChange);
|
||||
remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
} else {
|
||||
reachable = remoteHostReachability.TryGetFlags (out flags);
|
||||
}
|
||||
|
||||
if (!reachable)
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
if (!IsReachableWithoutRequiringConnection (flags))
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
return (flags & NetworkReachabilityFlags.IsWWAN) != 0 ?
|
||||
NetworkStatus.ReachableViaCarrierDataNetwork : NetworkStatus.ReachableViaWiFiNetwork;
|
||||
}
|
||||
|
||||
public static NetworkStatus InternetConnectionStatus ()
|
||||
{
|
||||
NetworkReachabilityFlags flags;
|
||||
bool defaultNetworkAvailable = IsNetworkAvailable (out flags);
|
||||
|
||||
if (defaultNetworkAvailable && ((flags & NetworkReachabilityFlags.IsDirect) != 0))
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
|
||||
return NetworkStatus.ReachableViaCarrierDataNetwork;
|
||||
|
||||
if (flags == 0)
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
return NetworkStatus.ReachableViaWiFiNetwork;
|
||||
}
|
||||
|
||||
public static NetworkStatus LocalWifiConnectionStatus ()
|
||||
{
|
||||
NetworkReachabilityFlags flags;
|
||||
if (IsAdHocWiFiNetworkAvailable (out flags))
|
||||
if ((flags & NetworkReachabilityFlags.IsDirect) != 0)
|
||||
return NetworkStatus.ReachableViaWiFiNetwork;
|
||||
|
||||
return NetworkStatus.NotReachable;
|
||||
}
|
||||
}
|
||||
}
|
Двоичные данные
ReachabilitySample/red.png
До Ширина: | Высота: | Размер: 503 B |