Tôi gặp khó khăn khi sử dụng Khả năng hiển thị trong mã của tôi. Tôi muốn giữ nó rất đơn giản bằng cách bắt đầu một người quan sát lúc khởi động và sau đó chỉ nhận được thông báo thay đổi. Trong đoạn mã sau, phương thức reachabilityChanged không bao giờ được gọi. Tôi đã thử nhiều lần lặp nhưng đây là phiên bản đơn giản nhất. Nó biên dịch và chạy. Xin vui lòng giúp ...Thông báo khả năng hiển thị Không bao giờ được gọi là
** * * đang AppDelegate.h * ** *
#import <UIKit/UIKit.h>
#ifdef PHONEGAP_FRAMEWORK
#import <PhoneGap/PGViewController.h>
#import <PhoneGap/PGURLProtocol.h>
#import <PhoneGap/Reachability.h>
#else
#import "PGViewController.h"
#import "PGURLProtocol.h"
#import "Reachability.h"
#endif
@interface AppDelegate : NSObject < UIApplicationDelegate, UIWebViewDelegate, PGCommandDelegate> {
NSString* invokeString;
}
@property (nonatomic, copy) NSString* invokeString;
@property (nonatomic, strong) IBOutlet UIWindow* window;
@property (nonatomic, strong) IBOutlet PGViewController* viewController;
@end
** * * Đoạn mã AppDelegate.m * ** *
#import "AppDelegate.h"
#import "MainViewController.h"
#ifdef PHONEGAP_FRAMEWORK
#import <PhoneGap/PGPlugin.h>
#import <PhoneGap/PGURLProtocol.h>
#import <PhoneGap/Reachability.h>
#else
#import "PGPlugin.h"
#import "PGURLProtocol.h"
#import "Reachability.h"
#endif
@implementation AppDelegate
@synthesize invokeString, window, viewController;
- (void) reachabilityChanged:(NSNotification *)notice
{
NSLog(@"???????? CODE NEVER GETS HERE ??????????");
Reachability *reach = [notice object];
NSParameterAssert([reach isKindOfClass: [Reachability class]]);
NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
if(remoteHostStatus == NotReachable) {NSLog(@"**** Not Reachable ****");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"**** wifi ****"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"**** cell ****"); }
}
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NetworkStatus remoteHostStatus = [reach currentReachabilityStatus];
NSLog(@”???? ALWAYS INITS WITH Not Reachable ????”);
if(remoteHostStatus == NotReachable) {NSLog(@"init **** Not Reachable ****");}
else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"int **** wifi ****"); }
else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"init **** cell ****"); }
// ...
}
@end
Chắc chắn danh hiệu và/hoặc thẻ có thể được cập nhật để làm cho câu hỏi này dễ nhận biết hơn ... –
Chỉ cần chỉnh sửa - tựa đề hy vọng và thẻ có nhiều tính mô tả hơn. –