ここからARC対応バージョンをDLして、プロジェクトに加える。
(追記 公式がアップデートしてARCに対応している https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html)
次にBuild PhasesのLink Binary With LibrariesでSystemConfiguration.frameworkを追加。
あとはヘッダを読み込んだファイルで以下を記述したら完了。
コード引用元
(追記 公式がアップデートしてARCに対応している https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html)
次にBuild PhasesのLink Binary With LibrariesでSystemConfiguration.frameworkを追加。
あとはヘッダを読み込んだファイルで以下を記述したら完了。
コード引用元
Reachability *reachablity = [Reachability reachabilityForInternetConnection];
NetworkStatus status = [reachablity currentReachabilityStatus];
switch (status) {
case NotReachable:
NSLog(@"インターネット接続出来ません");
break;
case ReachableViaWWAN:
NSLog(@"3G接続中");
break;
case ReachableViaWiFi:
NSLog(@"WiFi接続中");
break;
default:
NSLog(@"??[%d]", status);
break;
}
追記
オフラインかどうか調べたいだけなのでマクロにした
#define isOffline \
([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable ? YES : NO )
0 件のコメント:
コメントを投稿