• iOS 获取蜂窝信号强度

    2016-10-28 17:56:55
    调用CoreTelephony.framework的私有函数“CTGetSignalStrength”能够获取信号,如下:int getSignalStrength() { void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", ...

    调用CoreTelephony.framework的私有函数“CTGetSignalStrength”能够获取信号,如下:

    int getSignalStrength()
    {
    void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
    int (*CTGetSignalStrength)();
    CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
    if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength"); 
    int result = CTGetSignalStrength();
    dlclose(libHandle);
    return result;
    }
    展开全文
  • iOS 获取wifi信号强度

    2016-10-28 17:43:15
    虽然各种直接获取信号强度的api都被封杀了。但是还有一个另类的黑魔法可以获取到。那就是遍历UIStatusBar了- (void)getSignalStrength{ UIApplication *app = [UIApplication sharedApplication]; NSArray *...

    虽然各种直接获取信号强度的api都被封杀了。但是还有一个另类的黑魔法可以获取到。那就是遍历UIStatusBar了

    - (void)getSignalStrength{
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
        NSString *dataNetworkItemView = nil;
    
        for (id subview in subviews) {
            if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
                dataNetworkItemView = subview;
                break;
            }
        }
    
        int signalStrength = [[dataNetworkItemView valueForKey:@"_wifiStrengthBars"] intValue];
    
        NSLog(@"signal %d", signalStrength);
    }

    当然我们还可以遍历UIStatusBar 获取到网络连接类型

    - (void)getNetworkType
    {
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *subviews = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
        for (id subview in subviews) {
            if ([subview isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
                int networkType = [[subview valueForKeyPath:@"dataNetworkType"] intValue];
                switch (networkType) {
                    case 0:
                        NSLog(@"NONE");
                        break;
                    case 1:
                        NSLog(@"2G");
                        break;
                    case 2:
                        NSLog(@"3G");
                        break;
                    case 3:
                        NSLog(@"4G");
                        break;
                    case 5:
                    {
                        NSLog(@"WIFI");
                    }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    展开全文
  • Measuring cellular signal strength   ... I am developing a non-appstore app for iOS. I want to read the cellular signal st...

    Measuring cellular signal strength

     

    https://stackoverflow.com/questions/4954389/measuring-cellular-signal-strength

    I am developing a non-appstore app for iOS. I want to read the cellular signal strength in my code.

    I know Apple doesn't provide any API by which we can achieve this. 

    Is there any private API that can be used to achieve this? I have gone through the various threads regarding this issue but could not find any relevant info.

    It is completely possible because there is an app in the app-store for detecting the carrier's signal strength.

    ios iphone objective-c cocoa-touch

    shareimprove this question

    edited Feb 9 '15 at 22:30

    skrrgwasme

    6,912113763

    asked Feb 10 '11 at 7:17

    bhatti

    140126

    add a comment

    6 Answers

    activeoldestvotes

    9

     

    I briefly looked at the VAFieldTest project located at Github.

    There seems to be  getSignalStrength() and register_notification() functions in Classes/VAFieldTestViewController.m that might be interesting to you as they call into CoreTelephony.framework

    I am pretty confident that some of the used calls are undocumented in the CoreTelephony framework documentation from Apple and therefore private - any app in the AppStore must have slipped passed inspection. 

    shareimprove this answer

    answered Feb 10 '11 at 9:38

    Niels Castle

    7,4852553

    • @Niels Castle How can I convert the signal strength that I got using VAFieldTest application to dBm? – DeeMar 18 '13 at 11:47

    • Follow the link to Github and you'll be able to interact directly with Vlad, the maintainer of VAFieldTest. – Niels Castle Mar 18 '13 at 15:01

    • Is it possible to get other parameters as well : RSCP (signal level), SC (Scrambling Code) and EcNo (Signal To Noise Ratio)? – luksmir May 17 '13 at 6:27

    • The project crashes almost instantly on iOS 9. – Raptor Dec 3 '15 at 10:37

    • Any idea how OpenSignal does their signal strength measurement ? They show the technology and signal strength on their home screen (tested on iOS 10), and the value is very accurate. – user5365075 Aug 19 '17 at 14:26

    show 1 more comment

     

    14

     

    Get signalStreght IOS9: 

    UIApplication *app = [UIApplication sharedApplication];  
    NSArray *subviews = [[[app valueForKey:@"statusBar"]     valueForKey:@"foregroundView"] subviews];  
    NSString *dataNetworkItemView = nil;  
         for (id subview in subviews) {  
       if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarSignalStrengthItemView") class]])  
       {  
            dataNetworkItemView = subview;  
            break;  
        }  
     }  
    int signalStrength = [[dataNetworkItemView valueForKey:@"signalStrengthRaw"] intValue];  
    NSLog(@"signal %d", signalStrength);

    shareimprove this answer

    edited Dec 21 '15 at 6:02

    bummi

    25.1k85289

    answered Dec 21 '15 at 5:44

    vualoaithu

    864109

    add a comment

    10

     

    It is not very hard. 

    1. Link CoreTelephony.framework in your Xcode project
    2. Add the following lines where you need it

    Code:

    int CTGetSignalStrength(); // private method (not in the header) of Core Telephony
    
    - (void)aScanMethod
    {
        NSLog(@"%d", CTGetSignalStrength()); // or do what you want
    }

    And you are done.

    Update May 2016

    Apple removed this opportunity.

    shareimprove this answer

    edited Apr 29 '16 at 11:15

    answered Sep 18 '13 at 8:19

    Michael Dorner

    6,59094269

    add a comment

    5

     

    To get signal streght in iOS 9 or above in Swift 3, without using the private API from CoreTelephony - CTGetSignalStrength(). Just scouring the statusBar view.

    func getSignalStrength() -> Int {
    
        let application = UIApplication.shared
        let statusBarView = application.value(forKey: "statusBar") as! UIView
        let foregroundView = statusBarView.value(forKey: "foregroundView") as! UIView
        let foregroundViewSubviews = foregroundView.subviews
    
        var dataNetworkItemView:UIView!
    
        for subview in foregroundViewSubviews {
            if subview.isKind(of: NSClassFromString("UIStatusBarSignalStrengthItemView")!) {
                dataNetworkItemView = subview
                break
            } else {
                return 0 //NO SERVICE
            }
        }
    
        return dataNetworkItemView.value(forKey: "signalStrengthBars") as! Int
    
    }

    Attention: If the status bar is hidden, the key "statusBar" will return nil.

    shareimprove this answer

    edited Jun 14 '17 at 1:01

    answered Dec 15 '16 at 17:52

    Lucas Freitas de Oliveira

    5114

    show 3 more comments

    1

     

    I haven't tested it, but apparently this is now a method of CTTelephonyNetworkInfo instead of a global/static function.

    The return type is id, so I think you get either a NSDictionary (as the _cachedSignalStrengthivar implies) or an NSNumber (as the old function implies).

    id signalStrength = [[CTTelephonyNetworkInfo new] signalStrength];

    This changed in iOS 8.3, as you can see from the commit.

    Note that this is still not documented! So if your app will go in the App Store, take your precautions.

    shareimprove this answer

    edited Dec 3 '15 at 10:48

    Raptor

    34.7k31175287

    answered Jul 3 '15 at 15:50

    Alessandro Vendruscolo

    9,73232638

    • 2

      signalStrength returns null in iOS 9 – Raptor Dec 3 '15 at 10:59

    • I am trying to get the cellular signal strength for iOS 9 but as mentioned above its returning 0. Using UIStatusBarSignalStrengthItemView does not work in background mode so it is of no use as i need to get signal strength in background. Please let me know if anybody is able to get the values. – iOS Dev Sep 20 '16 at 12:33

    add a comment

    0

     

    Here's Lucas' answer converted to Xamarin, and tested on iOS 10.2.1:

    var application = UIApplication.SharedApplication;
    var statusBarView = application.ValueForKey(new NSString("statusBar")) as UIView;
    var foregroundView = statusBarView.ValueForKey(new NSString("foregroundView")) as UIView;
    
    UIView dataNetworkItemView = null;
    foreach (UIView subview in foregroundView.Subviews)
    {
        if ("UIStatusBarSignalStrengthItemView" == subview.Class.Name)
        {
            dataNetworkItemView = subview;
            break;
        }
    }
    if (null == dataNetworkItemView)
        return false; //NO SERVICE
    
    int bars = ((NSNumber)dataNetworkItemView.ValueForKey(new NSString("signalStrengthBars"))).Int32Value;

    shareimprove this answer

    answered Feb 1 '17 at 3:23

    Eliot Gillum

    417413

    add a comment

    展开全文
  • 虽然各种直接获取信号强度的api都被封杀了。但是还有一个另类的黑魔法可以获取到。那就是遍历UIStatusBar了 - (void)getSignalStrength{ UIApplication *app = [UIApplication sharedApplica

    原文链接:http://www.cnblogs.com/starainDou/p/5781130.html

    虽然各种直接获取信号强度的api都被封杀了。但是还有一个另类的黑魔法可以获取到。那就是遍历UIStatusBar了

    - (void)getSignalStrength{
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
        NSString *dataNetworkItemView = nil;
        
        for (id subview in subviews) {
            if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
                dataNetworkItemView = subview;
                break;
            }
        }
        
        int signalStrength = [[dataNetworkItemView valueForKey:@"_wifiStrengthBars"] intValue];
        
        NSLog(@"signal %d", signalStrength);
    }
    当然我们还可以遍历UIStatusBar 获取到网络连接类型

    - (void)getNetworkType
    {
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *subviews = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
        for (id subview in subviews) {
            if ([subview isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
                int networkType = [[subview valueForKeyPath:@"dataNetworkType"] intValue];
                switch (networkType) {
                    case 0:
                        NSLog(@"NONE");
                        break;
                    case 1:
                        NSLog(@"2G");
                        break;
                    case 2:
                        NSLog(@"3G");
                        break;
                    case 3:
                        NSLog(@"4G");
                        break;
                    case 5:
                    {
                        NSLog(@"WIFI");
                    }
                        break;
                    default:
                        break;
                }
            }
        }
    }


    展开全文
  • 此API是apple私有API,所以只可运用在越狱设备中,如果提交appstore,会遭遇apple的拒绝上架反馈! 1 #import <dlfcn.h> 2 ... 3 int getSignalLevel() ... 5 void *libHandle = dlopen("/System/Library/...

    此API是apple私有API,所以只可运用在越狱设备中,如果提交appstore,会遭遇apple的拒绝上架反馈!

     1 #import <dlfcn.h>
     2 
     3 int getSignalLevel()
     4 {
     5     void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony",RTLD_LAZY);//获取库句柄
     6     int (*CTGetSignalStrength)(); //定义一个与将要获取的函数匹配的函数指针
     7     CTGetSignalStrength = (int(*)())dlsym(libHandle,"CTGetSignalStrength"); //获取指定名称的函数
     8     
     9     if(CTGetSignalStrength == NULL)
    10         return -1;
    11     else{
    12         int level = CTGetSignalStrength();
    13         dlclose(libHandle); //切记关闭库
    14         return level;
    15     }  
    16 }

     

    转载于:https://www.cnblogs.com/zbblog/p/5522417.html

    展开全文
  • 在APP中,有时候需要对用户设备的网络状态进行实时监控,让用户了解自己的网络状态,根据用户的网络状态进行智能处理,节省用户流量,提高用户体验. 检测网络状态有多重方法,最常见的是 苹果官方提供了一个叫...
  • RT,不管返回来的是以数为变量,还是只有几种状态都行,只要能检测到目前连接的wifi强度信号量就可以。 -----------------------------------------------------------------------------------------------------...
  • 最近公司社区项目中要用到或者社区周围WiFi列表以及信号强度,好多网友说实现不了讨论区相关资源:APP跳转 及iOS10跳转在设置页面Wifi 定位原理及 iOS Wifi 列表获取iOS 获取系统wifi列表,wifi信号强度,并给wifi设置...
  • 1.虽然各种直接获取信号强度的api都被封杀了。但是还有一个另类的黑魔法可以获取到。那就是遍历UIStatusBar了 网络上有的文章写的会崩溃 比如: - (int)getSignalStrength{ if (iPhoneX) { id statusBar = ...
  • iOS状态栏操作之获取WiFi信号强度,WiFi名字和IP,网络类型,运营商,电池电量,系统时间等此篇文章讲述iOS中的状态栏iOS开发中对状态栏的操作比较少,因为状态栏是系统级别的View,是受苹果保护的,不可以随便更改...
  • iOS蓝牙 测试 代码 RSSI信号 获取 接收发送 数据
  • 获取iOS手机路由表
  • OS BLE 4.0 实现搜索周边蓝牙设备并显示其信号强度(RSSI) 源码:https://git.oschina.net/laughingzhong/MyBluetoothDemo.git 1. [代码][Objective-C]代码 跳至 
  • iOS 获取wifi强度

    2016-11-30 20:24:56
    可以获取wifi信号强度, 3, 2 ,1 // UIApplication *app = [UIApplication sharedApplication]; // NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subview
  • * 获取手机数据信号强度值工具类 * dbm的值为负数 * 0为最强信号值 * -85以内为满格信号 */ public class PhoneNetUtil { private static final int DBM_1 = -85; private static final int DBM_2 = -95; ...
  • 移动端游戏中无法看到电量与wifi信号对于玩家来说是很困扰的事。 关于这个问题安卓与iOS有不同的方法 电量 安卓 安卓获取电量有两种方法,一种是读取安卓手机里的一个文件,一种是利用安卓与Unity互...
  • 今天写的内容呢是判断当前手机是否有信号。。主要有两种方式: 1、通过打开“电话”输入 “ *3001#12345#* ”,按拨号键,跳转到Field Test界面,这时左上角的信号原点会显示成数字,接着再同时按下开机键和Home建...
1 2 3 4 5 ... 20
收藏数 1,571
精华内容 628