Face Book和Twitter集成到iPhone应用程序不起作用



我对iOS开发非常新。我已经完成了所有必需的编码,并且在模拟器上它工作正常,但在设备上不正常。

作为Facebook集成编码的另一个问题,我已从其他"演示"应用程序中抄袭了它。因此,我们需要更改它以使其用于我自己的应用程序。因为当我看到我的应用程序完成的更新时在Facebook墙上,"演示"应用程序名称随帖子而来。

请指导我!

facebook

看来,您在阅读文档之前已经跳到了编码部分。在集成Facebook SDK并编写代码之前,您需要在Facebook开发人员控制台中创建一个新的应用程序部分,请获取Facebook应用程序ID。您需要在项目中使用该应用ID,而不是使用Facebook Demo应用程序发货的应用ID。

文档充分说明了该过程,无需在此处重写。确保您阅读到最后。

Twitter

我不确定您在Twitter中是否也有问题(问题尚不清楚)。如果是,您应该告诉您如何连接到Twitter。但是总的来说,从您的问题的语气来看,您似乎还没有阅读文档,在各自的开发人员控制台中创建应用程序部分并获取应用程序ID。

我不知道您需要多少集成或您愿意需要iOS 6,但是在iOS 6中,整合Facebook和Twitter的集成更容易。

这就是所有代码:

在标题文件中:

#import "Social/Social.h"

在主文件中:

    //Twitter
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
                NSLog(@"Cancelled");
            } else {
                NSLog(@"Done!");
            }
            [controller dismissViewControllerAnimated:YES completion:Nil];
        };
        controller.completionHandler = myBlock;
        [controller setInitialText:@"Status Text"];
        [self presentViewController:controller animated:YES completion:Nil];
    } else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now. You must be online and signed into at least one Twitter account." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
    //Facebook
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
                NSLog(@"Cancelled");
            } else {
                NSLog(@"Done!");
            }
            [controller dismissViewControllerAnimated:YES completion:Nil];
        };
        controller.completionHandler = myBlock;
        [controller setInitialText:@""];
        [self presentViewController:controller animated:YES completion:Nil];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook Error" message:@"Either you are not logged into Facebook or your Facebook username and password are incorrect." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
    }

您可以使用共享套件框架,http://getsharekit.com

按在您的应用程序中集成到Twitter。尝试此代码

在self.fullimage写下图像的任何网址。

调用buildtweetsheet方法发布到Twitter。

导入Twitter.framework

导入

@property(非原子,强)tweetComposeViewController *_tweetSheet;

@synthesize _tweetsheet; - (void)buildtweetsheet{ nslog(@" buildtweetsheet");

_tweetSheet = [[TWTweetComposeViewController alloc] init];

UIImage *eimage=UIImage *eimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.fullimage]]];


[_tweetSheet setInitialText:@""];
[_tweetSheet addImage:eimage];
[_tweetSheet setInitialText:@""];
[self presentModalViewController:_tweetSheet animated:YES];
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result)
{
    if(result == TWTweetComposeViewControllerResultDone) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Done" message:@"Image Posted Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Image Posted Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    [self dismissModalViewControllerAnimated:YES];
};
[_tweetSheet setCompletionHandler:completionHandler];

}

最新更新