私はアプリ開発が初めてで、uiwebviews でいくつかのビューコントローラーを使用するアプリを作成しました。iPhoneがインターネットに接続されていないときにアラートビューを追加したい。別のコードを実装しようとしましたが、アラートビューがポップアップしません。
これが私のコードです。
//
// ViewControllersocialgo.h
// GO!SocialMedia
//
// Created by Adam Rais on 28/11/2012.
// Copyright (c) 2012 SocialGO. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Reachability.h"
@interface ViewControllersocialgo : UIViewController <UIWebViewDelegate>
@property (strong, nonatomic) IBOutlet UIWebView *socialgo;
@end
およびViewControllerpractical.m
//
// ViewControllerpractical.m
// GO!SocialMedia
//
// Created by Adam Rais on 28/11/2012.
// Copyright (c) 2012 SocialGO. All rights reserved.
//
#import "ViewControllersocialgo.h"
#import <sys/socket.h>
#import <netinet/in.h>
#import <SystemConfiguration/SystemConfiguration.h>
@interface ViewControllersocialgo ()
@end
@implementation ViewControllersocialgo
-(BOOL) isInternetAvailable {
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress);
if(reachability != NULL) {
//NetworkStatus retVal = NotReachable;
SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags(reachability, &flags)) {
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
{
// if target host is not reachable
return NO;
}
if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
{
// if target host is reachable and no connection is required
// then we'll assume (for now) that your on Wi-Fi
return YES;
}
if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) ||
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))
{
// ... and the connection is on-demand (or on-traffic) if the
// calling application is using the CFSocketStream or higher APIs
if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0)
{
// ... and no [user] intervention is needed
return YES;
}
}
if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
{
// ... but WWAN connections are OK if the calling application
// is using the CFNetwork (CFSocketStream?) APIs.
return YES;
}
}
}
return NO;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[_socialgo setDelegate:self];
NSString *fullURL=@"http://adam182testing.comoj.com/socialgo.html";
NSURL *url=[NSURL URLWithString:fullURL];
NSURLRequest *requestOBJ=[NSURLRequest requestWithURL:url];
[_socialgo loadRequest:requestOBJ];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ありがとう