arcgis网络分析可达性_在iPhone上检查网络可达性

本文介绍了在iPhone应用中如何使用Reachability类来检测网络连接状态,当网络状态发生变化时,订阅Notification Center并处理相应变化,从而及时提醒用户网络状况。
摘要由CSDN通过智能技术生成
arcgis网络分析可达性

arcgis网络分析可达性

No Connection

In some iPhone apps you need to check if there is a connection to the outside world. If the application depends on a connection to the internet, we will want to warn the user of the app, if he cannot connect currently. In programming your app you can for example make sure that a certain view is pushed whenever there is no connection available or when your server that you need to connect to is down. When the connection is back up, you can again remove that view or show the default view of your app.

在某些iPhone应用程序中,您需要检查是否与外界连接。 如果应用程序依赖于互联网连接,我们将要警告该应用程序的用户(如果他当前无法连接)。 例如,在对应用进行编程时,可以确保在没有可用连接或需要连接的服务器关闭时推送特定视图。 备份连接后,您可以再次删除该视图或显示应用程序的默认视图。

I want to show a simple way how to get notified using the reachability class. If you would like to see how to extensively use the class in a project setting, check out this elaborate tutorial:

我想展示一种简单的方法,如何使用可达性类获得通知。 如果您想了解如何在项目设置中广泛使用该类,请查看以下详细教程:

http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/

http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/

Here is a checklist for integrating an observer for the connection:

这是用于集成连接观察者的清单:

  1. Get the Reachability class from Apple, it has all the functionality we need to check if a connection is up/down

    从Apple获得Reachability类,它具有我们需要检查连接是否正常的所有功能。
  2. Import the class into your app

    将课程导入您的应用
  3. Initialize it and create an observer

    初始化并创建观察者
  4. Create a method that handles an alteration of the network status

    创建一个方法来处理网络状态的更改

Basically, we will subscribe to the Notification Center or kNetworkReachabilityChangedNotification which will send us notifications when a change happens. We will handle that change by checking the content of the message sent.

基本上,我们将订阅通知中心或kNetworkReachabilityChangedNotification,它们将在发生更改时向我们发送通知。 我们将通过检查已发送消息的内容来处理此更改。

After you get the Reachability class from Apple, import it in your AppDelegate. There we will do our initialization and add an observer. As well, we will put our method there.

从Apple获得Reachability类后,将其导入AppDelegate中。 在那里,我们将进行初始化并添加观察者。 同样,我们将把方法放在那里。

So, we are in your YourAppDelegate.m and import the Reachability class:

因此,我们在您的YourAppDelegate.m中,并导入Reachability类:

#import "Reachability.h"

In the applicationDidFinishLaunching Method we will do the initialization and add an observer:

applicationDidFinishLaunching方法中,我们将进行初始化并添加观察者:

// Set the host name to check:

[[Reachability sharedReachability]
     setHostName:@"www.yourserver.com"]];

// Enable the status notifications:

[Reachability sharedReachability].networkStatusNotificationsEnabled = YES; 

// Add an observer to the notification center and call the method
// handleReachability when there was a notification:

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(handleReachability: )
    name:@"kNetworkReachabilityChangedNotification" object:nil];

I am assuming that you defined some navigation controller and your view controllers. So, we want to get notified whenever the reachability changed. We will call the method handleReachability when that happens:

我假设您定义了一些导航控制器和视图控制器。 因此,我们希望在可达性发生变化时得到通知。 发生这种情况时,我们将调用方法handleReachability

-(void)handleReachability:(NSNotificationCenter*)notification{
 if([[Reachability sharedReachability] remoteHostStatus] == NotReachable)
 {
  // what happens when network/server down: 

  [navigationController pushViewController:self.mySecondViewController
   animated:YES];

 }else{

  [navigationController popToViewController:self.myFirstViewController
   animated:YES];

 }
}

And that’s it. I hope it helps. Enjoy!

就是这样。 希望对您有所帮助。 请享用!

翻译自: https://tympanus.net/codrops/2009/09/14/checking-network-reachability-iphone/

arcgis网络分析可达性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值