检测在iOS中启用私有api的热点 [英] detect hotspot enabling in iOS with private api's

查看:528
本文介绍了检测在iOS中启用私有api的热点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我想检测一下用户在iOS设备中启用了热点/网络共享的天气。我可以使用私人api知道它不会进入应用程序商店。

ok so i want to detect weather the user has enabled hotspot/tethering or not in a iOS device. I can use private api's knowing it wont make it to the app store.

我试图通过私人api的列表/运行时标题但有太多可以决定哪些可能会有所帮助。

i was trying to go through private api's list/ runtime headers but there are too many to decide which might be helpful.

或者我是否可以知道 UIApplicationWillChangeStatusBarFrameNotification 从私人api中被解雇(可能需要活动呼叫和激活的热点等)

or if i could get to know where UIApplicationWillChangeStatusBarFrameNotification gets fired from in private api's(probably called for active call and activated hotspot etc)

我试过这个检测个人热点并使用 CaptiveNetwork 但它只返回连接的wi-fi ssid而不是创建的热点。

i tried this detect personal hotspot and also used CaptiveNetwork but it only returns the connected wi-fi ssid and not the created hotspot.

任何共享的知识都将非常有用

any knowledge shared will be extremely helpful

更新:@creker

Update: @creker

使用上面的代码,编译器会显示错误SCDynamicStoreCreate不可用:在iOS上不可用。所以我进入了SCDynamicStore.ha第二改变以下

With the above code the compiler shows the error " SCDynamicStoreCreate is unavailable: not available on iOS. So i went into SCDynamicStore.h and changed the following

    SCDynamicStoreRef
SCDynamicStoreCreate            (
                    CFAllocatorRef          allocator,
                    CFStringRef         name,
                    SCDynamicStoreCallBack      callout,
                    SCDynamicStoreContext       *context
                    )               __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA);

to

    SCDynamicStoreRef
SCDynamicStoreCreate            (
                    CFAllocatorRef          allocator,
                    CFStringRef         name,
                    SCDynamicStoreCallBack      callout,
                    SCDynamicStoreContext       *context
                    )               __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_6_0);

现在我能够获得状态为1022和1023的字典。只是想通过更改来确认像这样的文件(以前没做过)我在归档构建(或任何其他问题)时会遇到任何问题,除此之外我们知道这段代码不会进入应用程序商店

now i am able to get the dictionary with the states 1022 and 1023. Just wanted to confirm by changing the file like this(not done before) will i have any problem in archiving build(or any other problem) other then the fact that we know this code won't make it to the app store

推荐答案

没有私有API



您可以通过使用C API枚举网络接口来检测活动的个人热点。当hotpost处于活动状态且有人连接到它时,将有 bridge 前缀的接口。在我的iPhone 5上,它是 bridge100 。如果禁用热点或没有连接到热点,则接口甚至不在列表中。

Without Private APIs

You can detect active personal hotspot by enumerating network interfaces using C APIs. When hotpost is active and someone is connected to it there will be interface with bridge prefix. On my iPhone 5 it's bridge100. If hotspot is disabled or no one is connected to it that interfaces will not even be in the list.

C API甚至会返回该网络中的IP地址和子网掩码。

C APIs will even return you IP address and subnet mask in that network.

这就是我的意思在我的应用程序中使用来检测活动热点。

That's what I'm using in my applications to detect active hotspot.

要获得SSID,您需要 [[UIDevice currentDevice] name] - 个人热点SSID始终与设备名称匹配。

To get SSID you need [[UIDevice currentDevice] name] - personal hotspot SSID always matches device name.

您可以使用以下代码获取有关个人热点的所有信息:

You can obtain all the information about personal hotspot using this code:

SCDynamicStoreRef sc = SCDynamicStoreCreate(NULL, CFSTR("com.apple.wirelessmodemsettings.MISManager"), NULL, NULL);
NSDictionary* info = (__bridge_transfer NSDictionary*)SCDynamicStoreCopyValue(sc, CFSTR("com.apple.MobileInternetSharing"));
CFRelease(sc);

info 字典看起来像这样热点是活跃的并且有连接:

info dictionary will look something like this when hotspot is active and has connections:

{
    Errnum = 0;
    ExternalInterfaces =     (
        "pdp_ip0"
    );
    Hosts =     {
        Current = 1;
        Max = 5;
        MoreAllowed = 1;
        Type =         {
            AirPort = 0;
            Bluetooth = 0;
            Ethernet = 0;
            "USB-Ethernet" = 1;
        };
    };
    InternalInterfaces =     (
        bridge100
    );
    Reason = 0;
    State = 1023;
    Version = 2;
} 

当热点处于活动状态但没有连接时:

When hotspot is active but there are no connections:

{
    Errnum = 0;
    ExternalInterfaces =     (
    );
    Hosts =     {
        Current = 0;
        Max = 5;
        MoreAllowed = 1;
        Type =         {
            AirPort = 0;
            Bluetooth = 0;
            Ethernet = 0;
            "USB-Ethernet" = 0;
        };
    };
    InternalInterfaces =     (
    );
    Reason = 0;
    State = 1023;
    Version = 2;
}

当热点未激活时:

{
    Errnum = 45;
    ExternalInterfaces =     (
    );
    Hosts =     {
        Current = 0;
        Max = 5;
        MoreAllowed = 1;
        Type =         {
            AirPort = 0;
            Bluetooth = 0;
            Ethernet = 0;
            "USB-Ethernet" = 0;
        };
    };
    InternalInterfaces =     (
    );
    Reason = 0;
    State = 1022;
    Version = 2;
}

密钥将无论活动连接如何,当热点处于活动状态时,等于 1023 。我不知道该值是否包含位标志。 iOS实际上是在检查值是否等于 1023

State key will be equal to 1023 when hotspot is active regardless of active connections. I don't know whether that value contains bit-flags or not. iOS is actually checking if value is equal to 1023.

SCDynamicStore API来自公共 SystemConfiguration 框架,但在iOS平台上标记为不可用。这意味着所有标头都在那里,你只需要复制没有 __ OSX_AVAILABLE_STARTING 宏的定义。

SCDynamicStore APIs are from public SystemConfiguration framework but marked as not available on iOS platform. That means all the headers are there, you just need to copy definitions without __OSX_AVAILABLE_STARTING macro.

您甚至可以观察到该设置的变化 - 您可以指定要注意哪个值的键。阅读Apple文档了解实现细节。

You can even observe changes to that setting - you can specify a key which value you want to observe. Read Apple documentation for implementation details.


所以我进入了SCDynamicStore .h并更改了以下内容

So i went into SCDynamicStore.h and changed the following

我不会这样做。它不应该导致任何问题,但对我来说,更改SDK标头不是一个好的解决方案。我建议如下。不要包含框架标头。使用 __ OSX_AVAILABLE_STARTING 更改或删除所需的所有方法,制作自己的标题。

I wouldn't do that. It shouldn't cause any problems but for me changing SDK headers is not a good solution. I suggest the following. Don't include the framework headers. Make your own header where you copy all the methods you need with __OSX_AVAILABLE_STARTING changed or removed.

这篇关于检测在iOS中启用私有api的热点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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