[英]Face book and twitter integration to iphone app not working on device
我對iOS開發非常陌生,正在開發一個需要將twitter和Facebook集成到牆上進行發布的應用程序。 我已經完成了所有必需的編碼,並且在模擬器上可以正常工作,但在設備上無法正常工作。
還有一個問題是Facebook集成的編碼,我已經從其他“演示”應用程序中復制了它。那么我們需要對其進行哪些更改以使其適合我自己的應用程序。因為當我在Facebook牆上看到我的應用程序完成了更新時,該帖子隨附了“ demo”應用名稱。
請指導我!謝謝!
臉書
在閱讀文檔之前,您似乎已跳到編碼部分。 在集成facebook sdk和編寫代碼之前,您需要在facebook開發人員控制台中創建一個新的應用程序部分,獲取一個Facebook應用程序ID。 您需要在項目中使用該應用程序ID,而不是Facebook演示應用程序隨附的應用程序ID。
文檔全面解釋了該過程,無需在此處重寫。 請確保您閱讀到最后。
推特
我不確定你在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];
}
您可以使用Share kit框架, http://getsharekit.com
根據在應用程序中集成Twitter,請嘗試以下代碼
在self.fullimage處寫入圖像的任何URL。
調用buildTweetSheet方法發布到Twitter。
導入Twitter.framework
@property(nonatomic,strong)TWTweetComposeViewController * _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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.