有任何事件或任何其他方式來檢測iPad或iPhone何時超出特定WiFi範圍。我搜索了這一點,只能找到可達性類,這也是我將不得不在連續檢查連接,這是不是在我的情況下首選。任何幫助將不勝感激...檢測設備是否超出WiFi範圍
回答
這是示例代碼,你可以用它來找到WIFI /互聯網conncetivity
.h文件中
@class Reachability;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
Reachability* wifiReach;
}
.m文件
**
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[HPViewController alloc] initWithNibName:@"HPViewController_iPhone" bundle:nil];
} else {
self.viewController = [[HPViewController alloc] initWithNibName:@"HPViewController_iPad" bundle:nil];
}
_navCon =[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = _navCon;
// Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the
// method "reachabilityChanged" will be called.
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
//Change the host name here to change the server your monitoring
wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
[wifiReach startNotifier];
[self showAlertOfInternetConncetion: wifiReach];
return YES;
}
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification*)note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self showAlertOfInternetConncetion: curReach];
}
- (void)showAlertOfInternetConncetion : (Reachability*) curReach
{
NetworkStatus netStatus = [curReach currentReachabilityStatus];
switch (netStatus)
{
case NotReachable:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet connection" message:@"Your internet connection has stopped working. Please check it." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Exit App", nil];
[alert show];
[alert release];
}
case ReachableViaWWAN:
{
NSLog(@"ReachableVia WWAN");
}
case ReachableViaWiFi:
{
NSLog(@"ReachableVia WiFi");
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
exit(0);
}
}
**
感謝您的答案將今天自己嘗試.... – spider1983
@ spider1983你試過這個,發現它的工作原理?如果沒有,請不要接受答案,直到您確定他們回答您的問題。此外,這只是你說你已經找到的可達性代碼,它不會爲你工作..... –
@NickBull哦確定我確定我已經退出知道方式本身...我會糾正.. .. 。 我爲此感到抱歉。 – spider1983
使用Apple的SCNetworkReachability類。閱讀SCNetworkReachability documentation。 測試使用:
(ReachabilityInst.currentReachabilityStatus().value == ReachableViaWiFi.value)
- 1. 檢測哪個BT設備超出範圍
- 2. 夫特檢測是否信標超出範圍
- 3. 如何檢測ScrollViewer是否超出其可用範圍
- 4. pygame.midi.MidiException:'設備ID無效,超出範圍。'
- 5. Android:檢測WiFi接入點是否仍在範圍
- 6. 當UITableViewCell超出範圍時檢測到
- 7. as3 - 檢測超出範圍值w/parseInt()
- 8. 陣列超出範圍檢測
- 9. C++ - 檢測超出範圍的訪問
- 10. 測試超出範圍
- 11. 檢查數組[鍵]是否設置?拋出:索引超出範圍
- 12. 我試圖檢查索引是否超出範圍,但我使用的代碼是索引超出範圍?
- 13. 如何列出我的wifi範圍內的所有設備iphone
- 14. 檢測wifi是否打開
- 15. yii檢測範圍是否在使用
- 16. 使用android檢測我周圍的wifi設備
- 17. 如何測試無符號__int64數字是否超出範圍
- 18. 如何檢查數組索引是否超出範圍SWIFT
- 19. C#檢查對象是否超出範圍(GUI)
- 20. 如何檢查二維數組是否超出範圍?
- 21. 如何檢查數組索引是否超出範圍?
- 22. 檢測列表視圖是否超出範圍並傳入新項目
- 23. 檢測連接到Wifi的Android設備
- 24. 檢測Android設備是否是用java
- 25. 檢測一個特定的WiFi網絡是否在觸及範圍內
- 26. 如何檢測設備是否是三星設備
- 27. Xamarin表單 - 如何檢測設備是否是觸摸設備?
- 28. 檢測設備是否關閉?
- 29. 檢測設備是否支持jQuery Mobile
- 30. 檢測設備是否鎖定
好,如果你應該這樣做的方式是「不首選」,還有什麼是首選? – jimpic
連續檢查wifi會減慢我的應用程序,因爲我已經有太多的後臺事件正在進行。如果我能得到一個事件,那麼將是最好的事情。 – spider1983
檢查http://stackoverflow.com/questions/11083369/ios-wifi-notification-api – jimpic