I am trying to monitor UIScreenCapturedDidChangeNotification
for screen recording status using hyperloop in my Titanium app. I've been trying for a while but I couldn't find any examples of using NotificationCenter or addObserver in hyperloop. Basically I am trying to bring the following native code into hyperloop with no luck:
if (@available(iOS 11.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleScreenCaptureChange)
name:UIScreenCapturedDidChangeNotification object:nil];
}
Here is my attempt that is not working:
//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);
Try changing a few things :-
UIScreenMonitor.addMethod
needs a colon eg. 'handleScreenRecording:'
addObserverSelectorNameObject
' function call the selector needs a colon eg. 'handleScreenRecording:'
'new'
keyword when instantiating a new instance of UIScreenMonitor
class.screenMonitor
also needs to persists for the duration that you need it (ie. not a local var) if it is not.Hope this works.