我有一个通过wifi与网络通话的应用程序.我的问题是wifi网络没有互联网连接,所以我想使用运营商网络与外界交谈,同时也连接到wifi.
我做了一些搜索,但没有找到解决我问题的方法.许多答案指的是Reachability,但Reachability类指示可用的连接但无法确认站点是否可访问(因为站点可能已关闭,因此足够公平).
基本上我想强制我的应用程序使用CDN的某些URL,即使它连接到它用于其他URL的WIFI网络.
这可以以编程方式完成吗?否则,用户必须手动打开/关闭wifi网络以使应用程序使用CDN.
谢谢
我将Xcode项目从运行在Xcode 4.2上的Mac移动到运行Xcode 4.5的另一个mac后,我收到以下错误.
"_SCError", referenced from:
-[RKReachabilityObserver scheduleObserver] in libRestKit.a(RKReachabilityObserver.o)
-[RKReachabilityObserver unscheduleObserver] in libRestKit.a(RKReachabilityObserver.o)
"_SCErrorString", referenced from:
-[RKReachabilityObserver scheduleObserver] in libRestKit.a(RKReachabilityObserver.o)
-[RKReachabilityObserver unscheduleObserver] in libRestKit.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityCreateWithAddress", referenced from:
+[Reachability reachabilityWithAddress:] in Reachability.o
+[Reachability reachabilityWithAddress:] in test1ViewController.o
-[RKReachabilityObserver initWithAddress:] in libRestKit.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityCreateWithName", referenced from:
+[Reachability reachabilityWithHostName:] in Reachability.o
+[Reachability reachabilityWithHostName:] in test1ViewController.o
-[RKReachabilityObserver initWithHost:] in libRestKit.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityGetFlags", referenced from:
-[Reachability connectionRequired] in Reachability.o
-[Reachability currentReachabilityStatus] in Reachability.o
-[Reachability connectionRequired] in test1ViewController.o
-[Reachability currentReachabilityStatus] in test1ViewController.o
-[RKReachabilityObserver getFlags] in libRestKit.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityScheduleWithRunLoop", referenced …Run Code Online (Sandbox Code Playgroud) 我使用CNCopySupportedInterfaces()来获取bssid并且它没有返回任何值.不知道为什么.
我的代码看起来像这样:
#import <SystemConfiguration/CaptiveNetwork.h>
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSLog(@"Connected at:%@",myDict);
NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict;
NSString * BSSID = [myDictionary objectForKey:@"BSSID"];
NSLog(@"bssid is %@",BSSID);
Run Code Online (Sandbox Code Playgroud)
的NSLog(@ "%@",CNCopySupportedInterfaces());
返回(null)
不确定是什么问题?需要一些指导
我有以下代码来确定是否有互联网连接。这段代码工作正常。我如何知道我是否突然失去连接
var reachability:Reachability?
reachability = Reachability()
self.reachability = Reachability.init()
if((self.reachability!.connection) != .none)
{
print("Internet available")
}
Run Code Online (Sandbox Code Playgroud)
可达性类是否具有报告连接是否断开的功能。如果无法解决可达性问题,其他选择是什么
我正在创建一个需要互联网的应用程序.我想在我的项目中使用可达性类,我想检测用户是否没有互联网连接,无论技术是wifi,Cellular.我想要一步一步的指导.
我在iPhone4上使用iOS4.1.我也在使用最新版本的Reachability代码.我的设备没有连接,但似乎代码等待超时,否则设备需要很长时间才能报告可达性状态.
这似乎不会发生在使用iPhone3gs的iOS4.0.1上.
还有其他人遇到过这个吗?除了开始一个新线程之外,有什么方法可以绕过它吗?
当我尝试构建使用可达性的项目时,我不断收到此错误(错误仅在我尝试实现可达性后出现):

我在互联网上阅读了其他一些帖子,但似乎没有任何效果.我添加了SystemConfiguration.framework(项目,构建阶段,+),但这不起作用(我已经在错误出现时添加了它).这是我实现文件的方式:
#import <UIKit/UIKit.h>
#import "Reachability.h"
@interface catalogDetailView : UIViewController{
}
-(void)checkNetwork;
@end
Run Code Online (Sandbox Code Playgroud)
然后在.m:
#import "catalogDetailView.h"
-(void)checkNetwork{
if ([self reachable]) {
NSLog(@"Connected to Network");
}
else {
NSLog(@"Connection Failed");
}
}
-(BOOL)reachable {
Reachability *r = [Reachability reachabilityWithHostName:@"apple.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if(internetStatus == NotReachable) {
return NO;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
所以,如果你能帮助那将是惊人的!! 谢谢;)卢克
这是一个例子:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus != NotReachable) {
// Internet is reachable. Start download in background.
} else {
// Create UIAlertView and tell user there is no functional internet!
}
Run Code Online (Sandbox Code Playgroud)
问题:我听说在某些情况下WiFi" 可能需要VPN on Demand连接 ".那么我该如何正确地通知用户有关无功能的互联网连接?我假设上面的代码不足以解决这个问题.
我希望能够在我的View加载时检查互联网连接.预先确定我的观点的内容.
我有以下viewDidLoad方法:
- (void)viewDidLoad {
[super viewDidLoad];
if(![self hasInternetConnection]){
NSLog(@"SHOW ORIGINAL DOC");
}
else{
NSLog(@"SHOW NEW DOC");
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为hasInternetConnection的方法如下:
- (BOOL)hasInternetConnection{
NSLog(@"Starting connection test");
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is reachable
internetReachableFoo.reachableBlock = ^(Reachability*reach){
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"We have internet");
return YES;
});
};
// Internet is not reachable
internetReachableFoo.unreachableBlock = ^(Reachability*reach){
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"We do not have internet");
return NO;
});
}; …Run Code Online (Sandbox Code Playgroud) 我最近开始研究由firebase提供支持的iOS应用程序.我想知道使用firebase的特殊位置/.info/connected是否是检测用户是否有互联网连接的好方法.我知道这通常是使用apple提供的可达性apis来完成的.以下是我的想法:在app委托中,我将设置这样的东西
func application(application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [NSObject: AnyObject]?) -> Bool {
//Configure some stuff
let connectedRef =
Firebase(url:"https://serengeti.firebaseio.com/.info/connected")
connectedRef.observeEventType(.Value, withBlock: { snapshot in
let connected = snapshot.value as? Bool
let userDefaults = NSUserDefaults.standardUserDefaults()
if connected != nil && connected! {
//User is connected
userDefaults.setBool(true, forKey: "connected")
} else {
//User not connected
userDefaults.setBool(false, forKey: "connected")
}
userDefaults.synchronize() //Force value into NSUserDefaults
}
Run Code Online (Sandbox Code Playgroud)
然后在我需要检查连接的功能中(例如,当他们点击facebook注册按钮时)我查找NSUserDefaults条目
func authWithFacebook() {
let userDefaults = NSUserDefaults.standardUserDefaults()
if userDefaults.boolForKey("connected") == false {
//Segue …Run Code Online (Sandbox Code Playgroud)