我正在尝试通过通知中心向通知中心发出通知node
,NodObjC
问题是:
$.NSUserNotificationCenter('defaultUserNotificationCenter')
总是返回null
而不是能够调用该deliverNotification
方法的对象?
有没有人有经验NodObjC
?
我通过设置一个挂钩来提供捆绑 ID 解决了这个问题。这是演示代码:
var $ = require('NodObjC');
$.import('Cocoa');
// hook the bundle id
($.NSBundle).getInstanceMethod('bundleIdentifier').setImplementation(function(value) {
return $('com.example.app1');
});
// test
var center = $.NSUserNotificationCenter('defaultUserNotificationCenter');
console.log(center); // output: <_NSConcreteUserNotificationCenter: 0x103821e90>