wifi网络改变时的iPhone通知 [英] iPhone notification when wifi network changes

查看:822
本文介绍了wifi网络改变时的iPhone通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对调整,因此目标是越狱设备,而不是应用商店。
我尝试在 SBWiFiManager 中挂钩不同的方法,但是当wifi强度改变(如此连续)或在网络改变后相当延迟之后,它们会被调用。

This is for a tweak, so the target is jailbroken devices, and not the app store. I have tried hooking different methods in the SBWiFiManager but they either are called when the wifi strength changes (so continuously) or after quite delay after the network has changed.

有没有其他方法可以获得通知(或其他方法来挂钩)wifi网络的变化?

Is there any other way to get a notification (or another method to hook) went the wifi network changes?

我知道你现在可以使用公共API获取当前的SSID,但我需要告知它何时发生变化。

I know you can get the current SSID with public APIs now, but I need to be told when it changes.

推荐答案

执行此操作的一种方法是从Core Foundation侦听 com.apple.system.config.network_change 事件达尔文通知中心。

One way to do this is to listen for the com.apple.system.config.network_change event from the Core Foundation Darwin notification center.

注册活动:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                NULL, // observer
                                onNotifyCallback, // callback
                                CFSTR("com.apple.system.config.network_change"), // event name
                                NULL, // object
                                CFNotificationSuspensionBehaviorDeliverImmediately);

这是一个回调示例:

static void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
    NSString* notifyName = (NSString*)name;
    // this check should really only be necessary if you reuse this one callback method
    //  for multiple Darwin notification events
    if ([notifyName isEqualToString:@"com.apple.system.config.network_change"]) {
        // use the Captive Network API to get more information at this point
        //  https://stackoverflow.com/a/4714842/119114
    } else {
        NSLog(@"intercepted %@", notifyName);
    }
}

参见我的另一个答案的链接,例如如何使用强制网络API获取当前的SSID。

See my link to another answer on how to use the Captive Network API to get the current SSID, for example.

请注意,虽然我测试过的手机是越狱(iOS 6.1),但我认为这不需要越狱才能正常工作。它当然不需要将应用程序安装在正常的沙箱区域之外( / var / mobile / Applications / * )。

Note that although the phone I tested this on is jailbroken (iOS 6.1), I don't think this requires jailbreaking to work correctly. It certainly doesn't require the app being installed outside the normal sandbox area (/var/mobile/Applications/*).

PS我没有详尽地测试这个,以了解此事件是否给出任何误报(基于您对网络更改的定义)。但是,只要存储一些状态变量就足够简单,等于最后一个网络的SSID,并在此事件发生时将其与当前变量进行比较。

P.S. I haven't tested this exhaustively enough to know whether this event gives any false positives (based on your definition of a network change). However, it's simple enough just to store some state variable, equal to the last network's SSID, and compare that to the current one, whenever this event comes in.

这篇关于wifi网络改变时的iPhone通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆