在我的iphone應用程序中,用戶可以設置他是否想通過wifi或3G/Carrier數據從互聯網上下載數據。如何從Carrier數據/ 3GS下載數據而不是WiFi?
我們如何以編程方式做到這一點?
換句話說,我如何強迫iphone從運營商數據中獲取數據,而不是從wifi?
任何建議傢伙?
在我的iphone應用程序中,用戶可以設置他是否想通過wifi或3G/Carrier數據從互聯網上下載數據。如何從Carrier數據/ 3GS下載數據而不是WiFi?
我們如何以編程方式做到這一點?
換句話說,我如何強迫iphone從運營商數據中獲取數據,而不是從wifi?
任何建議傢伙?
你不能強迫的iPhone如果手機連接到使用載波數據(3G /邊緣)而不是無線網絡無線上網。您可以使用SCNetworkReachabilityGetFlags函數來確定您是使用WiFi還是有載波數據連接。
您可以做的是,如果用戶連接到WiFi,則會彈出一條消息,指出您的應用只適用於運營商數據,並要求用戶關閉WiFi並重新啓動應用。雖然這不會阻止沃達豐葡萄牙爲他們的應用程序執行某些應用程序,但他們愚蠢地企圖迫使您使用更多(昂貴的)載體數據。
如果iPhone連接到WiFi,則無法以編程方式強制其使用蜂窩網絡進行下載。
爲此,您需要檢測手機的狀態,並且您可以輕鬆識別天氣數據在手機使用WiFi時不會傳輸。
-(void) viewWillAppear:(BOOL)animated
{
// check for internet connection
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
// check if a pathway to a random host exists
hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
[hostReachable startNotifier];
// now patiently wait for the notification
}
- (void) checkNetworkStatus:(NSNotification *)notice {
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus){
case NotReachable:
{
NSLog(@"The internet is down.");
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(@"A gateway to the host server is down.");
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(@"A gateway to the host server is working via WIFI.");
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(@"A gateway to the host server is working via WWAN.");
self.hostActive = YES;
break;
}
}
}
感謝您的回答。但這實際上不是問題。反正偉大的努力:) – Dilip 2012-01-05 12:57:17
你爲什麼要強迫別人使用載波數據,而不是無線網絡? – mluisbrown 2012-01-05 11:12:14