我尝试通过node和NodObjC向通知中心发送通知,但问题是:
$.NSUserNotificationCenter('defaultUserNotificationCenter')是否始终返回null,而不是能够调用deliverNotification方法的对象?
有没有人有使用NodObjC的经验?
发布于 2018-06-08 22:38:52
我通过设置一个钩子来提供包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>https://stackoverflow.com/questions/20678478
复制相似问题