我正在尝试使用Titanium应用程序中的hyperloop监视UIScreenCapturedDidChangeNotification
的屏幕录制状态。我已经尝试了一段时间,但找不到在hyperloop中使用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);
答案 0 :(得分:1)
尝试更改一些内容:-
UIScreenMonitor.addMethod
中的选择器名称需要冒号,例如。 'handleScreenRecording:'
addObserverSelectorNameObject
”函数调用中,选择器需要一个冒号,例如。 'handleScreenRecording:'
'new'
类的新实例时,添加一个UIScreenMonitor
关键字。screenMonitor
也需要持续存在(例如,不是本地变量)。希望这行得通。