问题
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