4

マウンテン ライオンでは、AppKit.framework の NSSharingService クラスを使用して、新しい共有の可能性を試しています。

この種のコードではすべてがうまくいきます

NSArray* array = @[ @"myText", [NSImage imageNamed:@"myImageFile"] ];

NSSharingService* sharingServiceFB = [NSSharingService sharingServiceNamed:NSSharingServiceNamePostOnFacebook];

[sharingServiceFB performWithItems:array];

しかし、私は performWithItems 関数によって生成された共有ウィンドウなしで同じことをしたいと思います. 私のアプリケーションのユーザーは、メッセージを送信することを確認したくないと考えているため、すでに選択しているためです。このクラスには「直接投稿」機能はありません。他の方法で行う必要がありますか?

4

1 に答える 1

2

Facebook の API を自分で実装する以外にこれを行う方法はありませんが、ウィンドウが 0.5 秒間表示されることを気にしない場合は、次のようにします。

- (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);
}

あなたのユーザーはそれを好まないかもしれません...

于 2013-04-13T01:52:30.943 に答える