简体   繁体   English

iOS 7,iPhone,接近传感器

[英]iOS 7, iPhone, Proximity Sensor

This is a short question but it was bugging me for a whole night. 这是一个简短的问题,但整夜困扰着我。 I have few of my own applications here (I write Objective-C Only and I use ARC) where if I write in appDelegate - application didFinishLaunching...: 我这里有一些自己的应用程序(我只写Objective-C,并且使用ARC),如果我在appDelegate中编写-应用程序didFinishLaunching ...:

[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateChanged:) name:UIDeviceProximityStateDidChangeNotification object:nil];

I get perfectly normal response. 我得到完全正常的反应。 Display turns off, I get notification with changed proximityState, etc. 显示屏关闭,我收到更改了接近状态的通知,等等。

Now, I have application that is not mine and I should modify it (I have Xcode project - source files). 现在,我的应用程序不是我的,我应该对其进行修改(我有Xcode项目-源文件)。 I only should implement some changes based on proximitySensor. 我仅应基于接近传感器实现一些更改。 I am absolutely unable to enable proximityMonitoring? 我绝对无法启用接近监控? I am doing the same thing as in other applications but it is simply not calling the notification and not changing proximityState. 我正在做与其他应用程序中相同的操作,但是它只是不调用通知并且不更改接近状态。 Biggest difference is that this application's appDelegate is .mm - mixed language, but I really don't think this should be a problem. 最大的区别是此应用程序的appDelegate是.mm-混合语言,但是我真的不认为这应该是一个问题。

Is there some GLOBAL way to disable sensors or only proximity sensor? 是否有某些禁用传感器或仅禁用接近传感器的全局方法? Can some service for recording audio or playing audio be able to disable proximity sensor? 某些用于录制音频或播放音频的服务可以禁用接近传感器吗? Any clue would be golden! 任何线索都是金色的! I really don't understand what could be preventing me from enabling this feature. 我真的不明白是什么会阻止我启用此功能。 Cheers everyone. 欢呼大家。

FUU! FUU!

ProximitySensor is being disabled if the application doesn't support Portrait orientation! 如果应用程序不支持纵向方向,则ProximitySensor将被禁用! You can do whatever you want, but if Portrait is not checked as a Device Orientation, ProximitySensor wont start up! 您可以做任何您想做的事,但是如果没有将Portrait作为设备方向进行检查,ProximitySensor将不会启动!

It's not clear what you're asking. 不清楚你在问什么。 When you say you "have an application that is not mine", do yo have the source code, or are you looking to patch it somehow? 当您说“您的应用程序不是我的”时,您是否拥有源代码,或者您是否希望以某种方式对其进行修补?

If you have the full source code you should be able to insert the same calls you show above and have them work. 如果您拥有完整的源代码,则应该可以插入上面显示的相同调用并使它们正常工作。 You would need to turn on proximity monitoring, add an observer, and then add your observer method to the class that you've added as an observer. 您将需要打开邻近监视,添加一个观察者,然后将您的观察者方法添加到作为观察者添加的类中。

I don't think you have to set a flag in the info.plist file in order to enable proximity monitoring, but I'm not positive. 我认为您不必在info.plist文件中设置标志即可启用接近度监视,但是我并不乐观。 I've only ever used it as an experiment, and that was a while ago. 我只是将它用作实验,那是前一段时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM