问题描述
在山狮上,我尝试与AppKit.framework的NSSharingService类共享新的可能性
On mountain lion, I try the new sharing possiblities with the NSSharingService class of AppKit.framework
使用这种代码,一切都很好
Everything goes fine with this kind of code
NSArray* array = @[ @"myText", [NSImage imageNamed:@"myImageFile"] ];
NSSharingService* sharingServiceFB = [NSSharingService sharingServiceNamed:NSSharingServiceNamePostOnFacebook];
[sharingServiceFB performWithItems:array];
但是我想在不执行performWithItems函数生成共享窗口的情况下执行相同的操作.由于我正在考虑应用程序的用户不想确认他要发送消息,因为他已经选择了该消息.我在该课程中没有看到任何直接发布"功能.是否需要以其他方式完成?
But I'd like to do the same without the sharing window generated by the performWithItems function.As I'm considering that the user of my application don't want to confirm that he want to send the message as he already have choosen that.I don't see any "direct posting" function in this class.Does it need to be done an other way ?
推荐答案
除了自己实现Facebook的API之外,没有其他方法可以执行此操作,但是如果您不介意窗口出现半秒钟,则可以这样做:
There is no way to do this other than implementing Facebook's API yourself, but if you don't mind the window appearing for half a second:
- (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);
}
您的用户可能不喜欢它...
Your users might not like it though...
这篇关于NSSharingService在不共享窗口的美洲狮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!