检测用户是否处于通话状态栏 [英] Detecting if user has in call status bar

查看:117
本文介绍了检测用户是否处于通话状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测用户是否处于通话中或网络共享?我有这样的iAd子视图:

How do I detect if user is in-call or tethering? I have a subview for iAd like this:

    _UIiAD = [[self appdelegate] UIiAD];
    _UIiAD.delegate = self;

    [_UIiAD setFrame:CGRectMake(0,470,320,50)];
    [self.view addSubview:_UIiAD];\

当它设置错误时用户正在通话?我如何检测到这一点?

And it sets it wrong when the user is in call? How do i detect this?

推荐答案

UIApplicationDelegate 有这两种方法。

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame;   // in screen coordinates
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame;

还有通知

UIApplicationWillChangeStatusBarFrameNotification
UIApplicationDidChangeStatusBarFrameNotification

但它们不会在应用推出时发布,所以我不推荐它。

but they're not posted on the launch of the app, so I wouldn't recommend it.

模拟器有一个有用的工具测试。

The simulator has an useful tool to test that.

Hardware->Toggle In-Call Status Bar

要实现,您必须在 AppDelegate.m 文件中实现这些方法。当状态栏改变它的高度时,将调用它们。其中一个在之前调用,另一个在更改之后调用。

To implement, you have to implement those methods on your AppDelegate.m file. They will be called when the status bar change it's height. One of them it's called before and the other after the change.

假设您希望通知 ViewController 当发生更改时,一个选项是发送通知。喜欢这个

Assuming you want that your ViewController to be notified when the change occurs, one option, is to send notifications. Like this

首先,在 AppDelegate.h上添加此属性

@property (assign, nonatomic) CGRect currentStatusBarFrame;

然后,在<$ c上实施 willChangeStatusBarFrame $ c> AppDelegate.m

then, implement willChangeStatusBarFrame on AppDelegate.m

- (void) application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
{
    self.currentStatusBarFrame = newStatusBarFrame;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Status Bar Frame Change"
                                                        object:self
                                                      userInfo:@{@"current status bar frame": [NSValue valueWithCGRect:newStatusBarFrame]}];

}

我们已经完成了我们的状态栏框架检查器。你需要知道状态栏框架的任何 ViewController 上实现的下一部分。

And we're done with the base of our Status Bar Frame Checker. The next part you implement on any ViewController that needs to know the status bar frame.

任何时候你想要得到状态栏框架,你真的喜欢这样吗

Any time you want to get the status bar frame, you do like so

[(AppDelegate*)[[UIApplication sharedApplication] delegate] currentStatusBarFrame]

要在更改时收到通知,请将其添加到 ViewDidLoad 方法。

And to be notified when it changes, add this to ViewDidLoad method.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(statusBarFrameChanged:)
                                             name:@"Status Bar Frame Change"
                                           object:[[UIApplication sharedApplication] delegate]];

并实施此方法

- (void) statusBarFrameChanged:(NSNotification*)notification
{
    CGRect newFrame = [[notification.userInfo objectForKey:@"current status bar frame"] CGRectValue];
    NSLog(@"new height %f", CGRectGetHeight(newFrame));
    // Here you do whatever you wanna do with the new height
}

这篇关于检测用户是否处于通话状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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