NSSharingService on mountain lion without sharing window

左心房为你撑大大i 提交于 2019-12-22 09:09:41

问题


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];

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 ?


回答1:


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...



来源:https://stackoverflow.com/questions/14053808/nssharingservice-on-mountain-lion-without-sharing-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!