這功能很重要
沒有apple會把你給退件!
1.先下載.h .m檔,這是ARC compatible版本
https://github.com/tonymillion/Reachability
2.使用no-wifi aleart教學
http://paulpeelen.com/2011/11/30/ios-4-ios-5-tutorial-uialertview-with-link-to-wifi-or-settings-app-using-reachability-and-xcode-4-2/
3.注意教學文是就算有3g沒wi-fi也提醒喔,所以改成
- (void)checkForHOSTConnection {
Reachability *hostReach = [Reachability reachabilityWithHostname:@"www.google.com"];
NSString *netStatus = [hostReach currentReachabilityString];
//NSLog(@"currentReachabilityString = %@", netStatus);
if ([netStatus isEqualToString:@"No Connection"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"已關閉\"行動數據\"", @"AlertView")message:NSLocalizedString(@"開啟行動數據或使用WI-FI來取用資料。", @"AlertView")delegate:self cancelButtonTitle:NSLocalizedString(@"好", @"AlertView")otherButtonTitles:NSLocalizedString(@"設定", @"AlertView"), nil];
[alertView show];
}
}
會比較適當
沒有留言:
張貼留言