6

我正在尝试通过通知中心向通知中心发出通知nodeNodObjC问题是:

    $.NSUserNotificationCenter('defaultUserNotificationCenter')

总是返回null而不是能够调用该deliverNotification方法的对象?

有没有人有经验NodObjC

4

1 回答 1

0

我通过设置一个挂钩来提供捆绑 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>
于 2018-06-08T14:38:52.047 回答