0

我正在尝试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);
4

1 回答 1

1

尝试改变一些东西:-

  1. 您的选择器名称UIScreenMonitor.addMethod需要一个冒号,例如。'handleScreenRecording:'
  2. 同样在您的 ' addObserverSelectorNameObject' 函数调用中,选择器需要一个冒号,例如。'handleScreenRecording:'
  3. 'new'实例化类的新实例时添加关键字UIScreenMonitor
  4. screenMonitor如果不是,还需要在您需要它的持续时间内持续存在(即不是本地变量)。

希望这有效。

于 2018-12-20T09:15:49.287 回答