objective-c – NSPasteboard generalPasteboard返回nil

我正在尝试从NSBundle中将NSString复制到粘贴板,该NSBundle作为插件加载到另一个程序中.

由于某种原因,[NSPasteboard generalPasteboard]返回零.

我的代码来自Apple的NSPasteboard documentationNSPasteboard programming guide

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];

// Outputs: (null)
NSLog(@"%@",pasteboard);

[pasteboard clearContents];
BOOL copiedToPasteboard = [pasteboard writeObjects:@[@"The string"]];

有没有什么我可以无意中做到这一点?

解决方法

我已经构建了一个最小的应用程序,它可以加载一个包并在每一步添加[NSPasteboard generalPasteboard]返回的值的记录.不幸的是,我无法重现这个问题.这是我得到的输出:

NUAppDelegate> init:<NSPasteboard: 0x100647740>
NUAppDelegate> awakeFromNib:<NSPasteboard: 0x100647740>
NUAppDelegate> applicationDidFinishLaunching::<NSPasteboard: 0x100647740>
Loading plugin
Plugin> init:<NSPasteboard: 0x100647740>
Plugin> someMethod:<NSPasteboard: 0x100647740>

没有更多细节,我看不出我们如何找到答案.你有一些我们可以下载或检查的代码吗?

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...