我已经找到了一些代码的例子来做我想做的事情(判断可达性),但没有一个看起来足够精确,对我有用.我不明白为什么这不想玩得很好.
我有可达性.h/m在我的项目中,我正在做
#import <SystemConfiguration/SystemConfiguration.h>
我添加了框架.我还有:
#import "Reachability.h"
在最高层.我试图使用可达性.
Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"http://www.google.com"]; // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];
if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFiNetwork) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {NSLog(@"cell"); }
这给我带来了各种各样的问题.我做错了什么?我是一个好的程序员,我只是很难弄清楚需要把什么放在哪里才能实现我想做的事情,不管我想不想知道我想做什么.(令人沮丧)
更新:事情就是这样.这是在我的viewcontroller中,我有
#import <SystemConfiguration/SystemConfiguration.h>
和
#import "Reachability.h"
set up with. This is my least favorite part of programming by far.
(source: sneakyness.com)
FWIW, we never ended up implementing this in our code. The two features that required internet access (entering the sweepstakes, 和 buying the dvd), were not main features. Nothing else required internet access.
Instead of adding more code, we just set the background of both internet views to a notice telling the users they must be connected to the internet to use this feature. It was in theme with the rest of the application's interface, 和 was done well/tastefully. They said nothing about it during the approval process, however we did get a personal phone call to verify that we were giving away items that actually pertained to the movie. According to their usually vague agreement, you aren't allowed to have sweepstakes otherwise.
我还认为这更严格地遵循了他们的"只有在你绝对需要的时候才使用"理念.