1

social.framework を使用して、Titanium Appcelerator の共有モジュールを作成しました。以下は私のコードです:

- (id) Facebook {

//if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
//{
    NSLog(@"Sharing via Facebook", nil);

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText: [dictPost valueForKey: @"post"]];
    [fbSheet addURL: [NSURL URLWithString: [dictPost valueForKey: @"link"]]];

    NSLog(@"Sharing via Facebook 2", nil);

    [[TiApp app] showModalController: fbSheet animated: YES];
    NSLog(@"Sharing via Facebook 3", nil);

/*} else {
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Post can't be shared. Please check Settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil] autorelease];
    [alert show];
}*/
}

- (id) Tweet {
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:SLServiceTypeTwitter];
    [tweetSheet setInitialText: [dictPost valueForKey: @"post"]];
    [[TiApp app] showModalController: tweetSheet animated: YES];
}

- (void) SharePost : (id) args {
    ENSURE_UI_THREAD(SharePost, args);
    ENSURE_UI_THREAD(Tweet, nil);
    ENSURE_UI_THREAD(Facebook, nil);

    NSArray *val = args;
    NSDictionary *dict = [[val objectAtIndex: 0] retain];

    dictPost = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [dict valueForKey: @"post"], [dict valueForKey: @"link"], [dict valueForKey: @"title"], [dict valueForKey: @"image"], nil] forKeys: [NSArray arrayWithObjects: @"post", @"link", @"title", @"image", nil]];

    if ([[dict valueForKey: @"type"] intValue] == 1) {
        [self Tweet];
    } else if ([[dict valueForKey: @"type"] intValue] == 2) {
        [self Facebook];
    }
}

電話するだけSharePostで、すべてのことをしてくれます。これは、Twitter と Facebook の両方で共有される唯一のコードです。しかし、FacebookでいくつかのURLを共有すると、ダイアログボックスが適切に表示され、 を選択するとPOST、数秒(約5秒)後にエラーが発生します。以下のエラーが発生

Facebook に投稿できません - Facebook への接続に失敗したため、投稿を送信できません。

そして、そのエラーから、「再試行」を選択すると、同じものが正常に投稿できます。ここにスクリーンショットを添付しました。

[共有] オプションが選択され、URL が共有されるように設定されている場合に開くダイアログ ボックス。

[投稿] ボタンが選択されたときのエラー メッセージ。

どなたかご存知の方いらっしゃいましたら教えてください。

4

0 に答える 0