зеркало из https://github.com/xamarin/ios-samples.git
Updated reachability sample
This commit is contained in:
Родитель
653a2d1a86
Коммит
5c42ffd8ae
|
@ -0,0 +1,5 @@
|
|||
*.exe
|
||||
*.mdb
|
||||
*.userprefs
|
||||
bin
|
||||
simulator
|
|
@ -1,11 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.02">
|
||||
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">512</int>
|
||||
<string key="IBDocument.SystemVersion">9C7010</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">654</string>
|
||||
<string key="IBDocument.AppKitVersion">949.26</string>
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<string key="IBDocument.SystemVersion">10B504</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">740</string>
|
||||
<string key="IBDocument.AppKitVersion">1038.22</string>
|
||||
<string key="IBDocument.HIToolboxVersion">457.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<string key="NS.object.0">62</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="7"/>
|
||||
|
@ -14,11 +18,23 @@
|
|||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBProxyObject" id="841351856">
|
||||
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
|
||||
</object>
|
||||
<object class="IBProxyObject" id="1071500409">
|
||||
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
|
||||
</object>
|
||||
<object class="IBUICustomObject" id="987256611"/>
|
||||
<object class="IBUIWindow" id="380026005">
|
||||
<reference key="NSNextResponder"/>
|
||||
|
@ -38,7 +54,7 @@
|
|||
<bool key="IBUIOpaque">NO</bool>
|
||||
<bool key="IBUIClipsSubviews">YES</bool>
|
||||
<bool key="IBUIUserInteractionEnabled">NO</bool>
|
||||
<string type="base64-UTF8" key="IBUIText"></string>
|
||||
<string key="IBUIText"/>
|
||||
<object class="NSColor" key="IBUITextColor">
|
||||
<int key="NSColorSpace">1</int>
|
||||
<bytes key="NSRGB">MSAwIDAAA</bytes>
|
||||
|
@ -46,7 +62,7 @@
|
|||
<nil key="IBUIHighlightedColor"/>
|
||||
<int key="IBUIBaselineAdjustment">1</int>
|
||||
<bool key="IBUIAdjustsFontSizeToFit">NO</bool>
|
||||
<float key="IBUIMinimumFontSize">1.400000e+01</float>
|
||||
<float key="IBUIMinimumFontSize">14</float>
|
||||
<int key="IBUINumberOfLines">0</int>
|
||||
<int key="IBUITextAlignment">1</int>
|
||||
</object>
|
||||
|
@ -116,9 +132,7 @@
|
|||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<object class="NSArray" key="object" id="957960031">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="object" ref="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
|
@ -129,18 +143,18 @@
|
|||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="388289409"/>
|
||||
</object>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="841351856"/>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">4</int>
|
||||
<reference key="object" ref="987256611"/>
|
||||
<reference key="parent" ref="957960031"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">ReachabilityAppDelegate</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
|
@ -157,13 +171,19 @@
|
|||
<reference key="object" ref="1041619883"/>
|
||||
<reference key="parent" ref="388289409"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="1071500409"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-1.CustomClassName</string>
|
||||
<string>-2.CustomClassName</string>
|
||||
<string>2.IBAttributePlaceholdersKey</string>
|
||||
<string>2.IBEditorWindowLastContentRect</string>
|
||||
<string>2.IBPluginDependency</string>
|
||||
|
@ -176,16 +196,15 @@
|
|||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>UIApplication</string>
|
||||
<string>UIResponder</string>
|
||||
<object class="NSMutableDictionary">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<string>{{536, 365}, {320, 480}}</string>
|
||||
<string>{{363, 365}, {320, 480}}</string>
|
||||
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
|
||||
<integer value="1"/>
|
||||
<string>ReachabilityAppDelegate</string>
|
||||
|
@ -196,9 +215,7 @@
|
|||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
|
@ -206,9 +223,7 @@
|
|||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
|
@ -224,7 +239,7 @@
|
|||
<string key="superclassName">NSObject</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>contentView</string>
|
||||
<string>summaryLabel</string>
|
||||
|
@ -245,7 +260,17 @@
|
|||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
|
||||
<integer value="512" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
|
||||
<integer value="3000" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">Reachability.xcodeproj</string>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
<string key="IBCocoaTouchPluginVersion">3.1</string>
|
||||
</data>
|
||||
</archive>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
// ------------------------------------------------------------------------------
|
||||
// <autogenerated>
|
||||
// This code was generated by a tool.
|
||||
// Mono Runtime Version: 2.0.50727.1433
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </autogenerated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace reachability {
|
||||
|
||||
|
||||
// Base type probably should be MonoTouch.Foundation.NSObject or subclass
|
||||
[MonoTouch.Foundation.Register("ReachabilityAppDelegate")]
|
||||
public partial class ReachabilityAppDelegate {
|
||||
|
||||
#pragma warning disable 0169
|
||||
[MonoTouch.Foundation.Connect("window")]
|
||||
private MonoTouch.UIKit.UIWindow window {
|
||||
get {
|
||||
return ((MonoTouch.UIKit.UIWindow)(this.GetNativeField("window")));
|
||||
}
|
||||
set {
|
||||
this.SetNativeField("window", value);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoTouch.Foundation.Connect("contentView")]
|
||||
private MonoTouch.UIKit.UIView contentView {
|
||||
get {
|
||||
return ((MonoTouch.UIKit.UIView)(this.GetNativeField("contentView")));
|
||||
}
|
||||
set {
|
||||
this.SetNativeField("contentView", value);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoTouch.Foundation.Connect("summaryLabel")]
|
||||
private MonoTouch.UIKit.UILabel summaryLabel {
|
||||
get {
|
||||
return ((MonoTouch.UIKit.UILabel)(this.GetNativeField("summaryLabel")));
|
||||
}
|
||||
set {
|
||||
this.SetNativeField("summaryLabel", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,150 +1,183 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Net;
|
||||
using MonoTouch.CoreGraphics;
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using MonoTouch.SystemConfiguration;
|
||||
using MonoTouch.CoreFoundation;
|
||||
|
||||
public partial class ReachabilityAppDelegate : UIApplicationDelegate {
|
||||
public string Hostname = "www.apple.com";
|
||||
UIImage imageCarrier, imageWiFi, imageStop;
|
||||
NetworkReachability nr;
|
||||
UITableView tableView;
|
||||
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
imageCarrier = UIImage.FromFile ("WWAN5.png");
|
||||
imageWiFi = UIImage.FromFile ("Airport.png");
|
||||
imageStop = UIImage.FromFile ("stop-32.png");
|
||||
|
||||
nr = new NetworkReachability ("www.apple.com");
|
||||
nr.SetCallback (ReachabilityChanged);
|
||||
nr.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
|
||||
AddTable ();
|
||||
//UpdateStatus ();
|
||||
//UpdateCarrierWarning ();
|
||||
|
||||
window.MakeKeyAndVisible ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Invoked on the main loop when reachability changes
|
||||
//
|
||||
void ReachabilityChanged (NetworkReachabilityFlags flags)
|
||||
{
|
||||
}
|
||||
|
||||
void AddTable ()
|
||||
{
|
||||
RectangleF tableFrame = UIScreen.MainScreen.ApplicationFrame;
|
||||
namespace reachability {
|
||||
public partial class ReachabilityAppDelegate : UIApplicationDelegate {
|
||||
UITableView tableView;
|
||||
NetworkStatus remoteHostStatus, internetStatus, localWifiStatus;
|
||||
|
||||
tableView = new UITableView (tableFrame, UITableViewStyle.Grouped) {
|
||||
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
|
||||
RowHeight = 44.0f,
|
||||
SeparatorStyle = UITableViewCellSeparatorStyle.None,
|
||||
SectionHeaderHeight = 28.0f,
|
||||
ScrollEnabled = false,
|
||||
Delegate = new TableViewDelegate (),
|
||||
DataSource = new DataSource (this)
|
||||
};
|
||||
|
||||
contentView.InsertSubviewBelow (tableView, summaryLabel);
|
||||
contentView.BringSubviewToFront (summaryLabel);
|
||||
tableView.ReloadData ();
|
||||
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
|
||||
{
|
||||
AddTable ();
|
||||
UpdateStatus ();
|
||||
//UpdateCarrierWarning ();
|
||||
|
||||
window.MakeKeyAndVisible ();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Invoked on the main loop when reachability changes
|
||||
//
|
||||
void ReachabilityChanged (NetworkReachabilityFlags flags)
|
||||
{
|
||||
UpdateStatus ();
|
||||
}
|
||||
|
||||
void UpdateStatus ()
|
||||
{
|
||||
remoteHostStatus = Reachability.RemoteHostStatus ();
|
||||
internetStatus = Reachability.InternetConnectionStatus ();
|
||||
localWifiStatus = Reachability.LocalWifiConnectionStatus ();
|
||||
}
|
||||
|
||||
|
||||
void AddTable ()
|
||||
{
|
||||
RectangleF tableFrame = UIScreen.MainScreen.ApplicationFrame;
|
||||
|
||||
tableView = new UITableView (tableFrame, UITableViewStyle.Grouped) {
|
||||
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
|
||||
RowHeight = 44.0f,
|
||||
SeparatorStyle = UITableViewCellSeparatorStyle.None,
|
||||
SectionHeaderHeight = 28.0f,
|
||||
ScrollEnabled = false,
|
||||
|
||||
Source = new DataSource (this),
|
||||
};
|
||||
|
||||
contentView.InsertSubviewBelow (tableView, summaryLabel);
|
||||
contentView.BringSubviewToFront (summaryLabel);
|
||||
tableView.ReloadData ();
|
||||
}
|
||||
|
||||
public override void OnActivated (UIApplication application)
|
||||
{
|
||||
Console.WriteLine ("OnActivated");
|
||||
}
|
||||
|
||||
class DataSource : UITableViewSource {
|
||||
ReachabilityAppDelegate parent;
|
||||
UIImage imageCarrier, imageWiFi, imageStop;
|
||||
|
||||
public DataSource (ReachabilityAppDelegate parent)
|
||||
{
|
||||
imageCarrier = UIImage.FromFile ("WWAN5.png");
|
||||
imageWiFi = UIImage.FromFile ("Airport.png");
|
||||
imageStop = UIImage.FromFile ("stop-32.png");
|
||||
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public override NSIndexPath WillSelectRow (UITableView view, NSIndexPath index)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override int RowsInSection (UITableView view, int section)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override int NumberOfSections (UITableView view)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public override string TitleForHeader (UITableView view, int 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";
|
||||
}
|
||||
}
|
||||
|
||||
static NSString ReachabilityTableCellIdentifier = new NSString ("ReachabilityTableCell");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var row = indexPath.Row;
|
||||
string text = "";
|
||||
UIImage image = null;
|
||||
switch (indexPath.Section){
|
||||
case 0:
|
||||
switch (parent.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 (parent.internetStatus){
|
||||
case NetworkStatus.NotReachable:
|
||||
text = "Access not available";
|
||||
image = imageStop;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaCarrierDataNetwork:
|
||||
text = "Avaialble via data carrier network";
|
||||
image = imageCarrier;
|
||||
break;
|
||||
case NetworkStatus.ReachableViaWiFiNetwork:
|
||||
text = "Available via WiFi network";
|
||||
image = imageWiFi;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (parent.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 ReachabilitChanged (NSNotification note)
|
||||
{
|
||||
Console.WriteLine ("reachability changed");
|
||||
}
|
||||
|
||||
void UpdateStatus ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnActivated (UIApplication application)
|
||||
{
|
||||
Console.WriteLine ("OnActivated");
|
||||
}
|
||||
|
||||
class TableViewDelegate : UITableViewDelegate {
|
||||
public override NSIndexPath WillSelectRow (UITableView view, NSIndexPath index)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class DataSource : UITableViewDataSource {
|
||||
ReachabilityAppDelegate parent;
|
||||
|
||||
public DataSource (ReachabilityAppDelegate parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public override int RowsInSection (UITableView view, int section)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override int NumberOfSections (UITableView view)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public override string TitleForHeader (UITableView view, int section)
|
||||
{
|
||||
switch (section){
|
||||
case 0:
|
||||
return parent.Hostname;
|
||||
case 1:
|
||||
return "Access to internet hosts";
|
||||
case 2:
|
||||
return "Access to Local Bonjour Hosts";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static NSString ReachabilityTableCellIdentifier = new NSString ("ReachabilityTableCell");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var row = indexPath.Row;
|
||||
switch (indexPath.Section){
|
||||
case 0:
|
||||
cell.TextLabel.Text = "First";
|
||||
break;
|
||||
case 1:
|
||||
cell.TextLabel.Text = "First";
|
||||
break;
|
||||
case 2:
|
||||
cell.TextLabel.Text = "First";
|
||||
break;
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
class Demo {
|
||||
static void Main (string [] args)
|
||||
{
|
||||
UIApplication.Main (args, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Demo {
|
||||
static void Main (string [] args)
|
||||
{
|
||||
UIApplication.Main (args, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using MonoTouch.Foundation;
|
||||
using MonoTouch.UIKit;
|
||||
using MonoTouch.SystemConfiguration;
|
||||
using MonoTouch.CoreFoundation;
|
||||
|
||||
public class Reachability {
|
||||
|
||||
public bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags)
|
||||
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;
|
||||
|
@ -22,7 +31,7 @@ public class Reachability {
|
|||
}
|
||||
|
||||
// Is the host reachable with the current network configuration
|
||||
public bool IsHostReachable (string host)
|
||||
public static bool IsHostReachable (string host)
|
||||
{
|
||||
if (host == null || host.Length == 0)
|
||||
return false;
|
||||
|
@ -37,10 +46,94 @@ public class Reachability {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Is 169.254.0.0 reachable (ad-hoc wifi
|
||||
// TODO: need to implement socket address probing
|
||||
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
var h = ReachabilityChanged;
|
||||
if (h != null)
|
||||
h (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){
|
||||
adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte [] {169,254,0,0}));
|
||||
adHocWiFiNetworkReachability.SetCallback (OnChange);
|
||||
adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
|
||||
if (!adHocWiFiNetworkReachability.TryGetFlags (out flags))
|
||||
return false;
|
||||
|
||||
return IsReachableWithoutRequiringConnection (flags);
|
||||
}
|
||||
|
||||
static NetworkReachability defaultRouteReachability;
|
||||
static bool IsNetworkAvaialable (out NetworkReachabilityFlags flags)
|
||||
{
|
||||
if (defaultRouteReachability == null){
|
||||
defaultRouteReachability = new NetworkReachability (new IPAddress (0));
|
||||
defaultRouteReachability.SetCallback (OnChange);
|
||||
defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
if (defaultRouteReachability.TryGetFlags (out flags))
|
||||
return false;
|
||||
return IsReachableWithoutRequiringConnection (flags);
|
||||
}
|
||||
|
||||
static NetworkReachability remoteHostReachability;
|
||||
public static NetworkStatus RemoteHostStatus ()
|
||||
{
|
||||
if (remoteHostReachability == null){
|
||||
remoteHostReachability = new NetworkReachability (HostName);
|
||||
remoteHostReachability.SetCallback (OnChange);
|
||||
remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
|
||||
}
|
||||
NetworkReachabilityFlags flags;
|
||||
if (!remoteHostReachability.TryGetFlags (out flags))
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
if (!IsReachableWithoutRequiringConnection (flags))
|
||||
return NetworkStatus.NotReachable;
|
||||
|
||||
if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
|
||||
return NetworkStatus.ReachableViaCarrierDataNetwork;
|
||||
|
||||
return NetworkStatus.ReachableViaWiFiNetwork;
|
||||
}
|
||||
|
||||
public static NetworkStatus InternetConnectionStatus ()
|
||||
{
|
||||
NetworkReachabilityFlags flags;
|
||||
bool defaultNetworkAvailable = IsNetworkAvaialable (out flags);
|
||||
if (defaultNetworkAvailable){
|
||||
if ((flags & NetworkReachabilityFlags.IsDirect) != 0)
|
||||
return NetworkStatus.NotReachable;
|
||||
} else if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
|
||||
return NetworkStatus.ReachableViaCarrierDataNetwork;
|
||||
return NetworkStatus.ReachableViaWiFiNetwork;
|
||||
}
|
||||
|
||||
public static NetworkStatus LocalWifiConnectionStatus ()
|
||||
{
|
||||
NetworkReachabilityFlags flags;
|
||||
if (IsAdHocWiFiNetworkAvailable (out flags)){
|
||||
if ((flags & NetworkReachabilityFlags.IsDirect) != 0)
|
||||
return NetworkStatus.ReachableViaWiFiNetwork;
|
||||
}
|
||||
return NetworkStatus.NotReachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{E1356D0A-1572-4157-BD97-05F0B9DA832E}</ProjectGuid>
|
||||
<ProjectTypeGuids>{E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>reachability</RootNamespace>
|
||||
<MainNibFile>MainWindow.xib</MainNibFile>
|
||||
<AssemblyName>reachability</AssemblyName>
|
||||
<MtouchSdkVersion>3.0</MtouchSdkVersion>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<BundleIcon>icon.png</BundleIcon>
|
||||
</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>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchDebug>True</MtouchDebug>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchDebug>False</MtouchDebug>
|
||||
</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>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>True</MtouchDebug>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>False</MtouchDebug>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="monotouch" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainWindow.xib.designer.cs">
|
||||
<DependentUpon>MainWindow.xib</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="reachability.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="MainWindow.xib" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
<Properties InternalTargetFrameworkVersion="IPhone" />
|
||||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
<ItemGroup>
|
||||
<Content Include="Network.png" />
|
||||
<Content Include="Airport.png" />
|
||||
<Content Include="stop-32.png" />
|
||||
<Content Include="WWAN5.png" />
|
||||
<Content Include="icon.png" />
|
||||
<Content Include="Default.png" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "reachability", "reachability.csproj", "{E1356D0A-1572-4157-BD97-05F0B9DA832E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||
Debug|iPhone = Debug|iPhone
|
||||
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
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = reachability.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Загрузка…
Ссылка в новой задаче