在山狮上,我尝试使用 AppKit.framework 的 NSSharingService 类来实现新的共享可能性
这种代码一切顺利
NSArray* array = @[ @"myText", [NSImage imageNamed:@"myImageFile"] ];
NSSharingService* sharingServiceFB = [NSSharingService sharingServiceNamed:NSSharingServiceNamePostOnFacebook];
[sharingServiceFB performWithItems:array];
但我想在没有 PerformWithItems 函数生成的共享窗口的情况下执行相同的操作。 当我考虑到我的应用程序的用户不想确认他想要发送消息时,因为他已经选择了这一点。 我在这个类中没有看到任何“直接发布”功能。 是否需要以其他方式完成?
最佳答案
除了自己实现 Facebook 的 API 之外,没有其他办法可以做到这一点,但如果您不介意窗口出现半秒:
- (void)whatever {
NSArray* array = @[ @"myText", [NSImage imageNamed:@"myImageFile"] ];
NSSharingService* sharingServiceFB = [NSSharingService sharingServiceNamed:NSSharingServiceNamePostOnFacebook];
[sharingServiceFB performWithItems:array];
[self performSelector:@selector(pressReturn) withObject:nil afterDelay:0.5];
}
- (void)pressReturn {
CGEventRef keypress = CGEventCreateKeyboardEvent(NULL, 36, TRUE);
CGEventPost(kCGHIDEventTap, keypress);
}
但您的用户可能不喜欢它...
关于custom-controls - 没有共享窗口的山狮上的 NSSharingService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14053808/