应用程序在后台运行时检测Wi-Fi网络更改

时间:2015-07-10 10:45:01

标签: ios objective-c iphone network-programming

我发现自2011年以来没有答案的this question,建议使用Reachability苹果示例代码,以便在网络发生变化时从iOS应用中进行检测(在后台运行时)。

我需要能够在应用程序处于后台时这样做,但代码示例没有显示后台执行。

我对如何做到这一点有任何想法?

这是我到目前为止写的AppDelegate代码:

#import "APLAppDelegate.h"
//#import "Reachability.h"

@implementation APLAppDelegate
@synthesize reachability;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Initialize Reachability


    //Reachability *

    reachability = [Reachability reachabilityForLocalWiFi];

    return YES;
}


- (void) applicationDidEnterBackground:(UIApplication *)application{
    // Start Monitoring
    [reachability startNotifier];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityDidChange:) name:kReachabilityChangedNotification object:nil];
}

- (void)reachabilityDidChange:(NSNotification *)notification {
    //Reachability *reachability = (Reachability *)[notification object];
    Reachability *reachability = (Reachability *)[notification object];

}

0 个答案:

没有答案