ios - Titanium 使用 NSNotificationCenter 使用 Hyperloop
问题描述
我正在尝试UIScreenCapturedDidChangeNotification
在我的 Titanium 应用程序中使用超级循环监控屏幕录制状态。我已经尝试了一段时间,但我找不到在超级循环中使用 NotificationCenter 或 addObserver 的任何示例。基本上我试图将以下本机代码带入超级循环,但没有运气:
if (@available(iOS 11.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleScreenCaptureChange)
name:UIScreenCapturedDidChangeNotification object:nil];
}
这是我的尝试不起作用:
//Add event listener to monitor screen recording.
var NotificationCenter = require('Foundation/NSNotificationCenter');
var UIScreenMonitor = Hyperloop.defineClass('UIScreenMonitor', 'NSObject');
UIScreenMonitor.addMethod({
selector : 'handleScreenRecording',
instance : true,
arguments : ['NSNotification'],
callback : function(screen) {
alert('Screen recording changed: '+UIScreen.mainScreen.isCaptured());
console.log('Screen recording changed: ',UIScreen.mainScreen.isCaptured(),screen.isCaptured());
}
});
var screenMonitor = UIScreenMonitor();
NotificationCenter.defaultCenter.addObserverSelectorNameObject(screenMonitor,'handleScreenRecording',UIScreen.UIScreenCapturedDidChangeNotification,null);
解决方案
尝试改变一些东西:-
- 您的选择器名称
UIScreenMonitor.addMethod
需要一个冒号,例如。'handleScreenRecording:'
- 同样在您的 '
addObserverSelectorNameObject
' 函数调用中,选择器需要一个冒号,例如。'handleScreenRecording:'
'new'
实例化类的新实例时添加关键字UIScreenMonitor
。screenMonitor
如果不是,还需要在您需要它的持续时间内持续存在(即不是本地变量)。
希望这有效。
推荐阅读
- javascript - 无法在用户上下文中读取 null 的属性“innerHTML”。
- javascript - 为什么反应显示组件更新但控制台不更新?
- docker - 容器之间的连接被拒绝:Docker
- r - ggplot的色谱图
- asp.net-core-mvc - JsonRequestBehavior.AllowGet 在当前上下文中不存在
- mongodb - Mongoose .pull 不删除子文档
- java - 无法将孩子添加到firebase android中的现有孩子
- android - 如何从 Firestore 获取子集合数据
- c++ - 为什么命名空间中的函数看不到我的 operator<< 全局定义?
- javascript - 如何对对象内数组属性的长度求和