Desidero sapere come pubblicare un messaggio di stato su Facebook su iOS 6 utilizzando i nuovi framework su Xcode 4.5. Grazie! :)Come postare su Facebook su iOS 6 in Objective-C utilizzando la classe ACAccountStore
risposta
La pubblicazione di un messaggio è piuttosto semplice. È quasi come con il Twitter Framework.
Per prima cosa è necessario importare i quadri: sociali e Bilancio
#import <Social/Social.h>
#import <Accounts/Accounts.h>
Nel file .h:
SLComposeViewController *mySLComposerSheet;
Questo codice deve essere inserito all'interno della vostra azione nel file .m:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked
{
mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social platform to use it, e.g. facebook or twitter
[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Test",mySLComposerSheet.serviceType]]; //the message you want to post
[mySLComposerSheet addImage:yourimage]; //an image you could post
//for more instance methods, go here: https://developer.apple.com/documentation/social/slcomposeviewcontroller#//apple_ref/doc/uid/TP40012205
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successful";
break;
default:
break;
} //check if everything worked properly. Give out a message on the state.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
@Blade thans. ma voglio condividere il messaggio senza foglio di azione come "TWRequest", quindi qual è il processo in facebook? – Hitarth
@Blade Grt suggetion. funziona bene, ma ho una query quando invio di nuovo lo stesso messaggio di quello che sto ottenendo due popup. 1. Post successfull e 2. Il post non può essere inviato perché la connessione a Facebook fallisce. Voglio solo un popup in modo che l'utente ottenga l'idea. Da questo due utenti popup si confondono il successo del post o meno. Per favore suggeriscimi se hai qualche idea. – Hitarth
@Blade possiamo cambiare "condiviso il collegamento tramite iOS" Per "condiviso il collegamento tramite MyAppName"? – Hitarth
e che cosa devo fare, quando voglio solo ricevere un avviso nel caso in cui il posto ha avuto successo, e nulla quando l'utente ha cancellato il post?
E sfortunatamente questo non funziona correttamente per Twitter ... Non rifiuta più il TweetSheet. Ecco il mio codice:
if(NSClassFromString(@"SLComposeViewController") != nil)
{
mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; //Tell him with what social plattform to use it, e.g. facebook or twitter
[mySLComposerSheet setInitialText:[NSString stringWithFormat:story.title,mySLComposerSheet.serviceType]]; //the message you want to post
[mySLComposerSheet addURL:[NSURL URLWithString:story.link]];
//for more instance methodes, go here:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = NSLocalizedStringFromTable(@"As it seems you didn't want to post to Twitter", @"ATLocalizable", @"");
break;
case SLComposeViewControllerResultDone:
output = NSLocalizedStringFromTable(@"You successfully posted to Twitter", @"ATLocalizable", @"");
break;
default:
break;
} //check if everything worked properly. Give out a message on the state.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
Ok ragazzi, quindi ho ottimizzato il post originale, funziona per iOS 6/7. Cambia ServiceType, Alert Title e Message per Facebook. Godere!
- (IBAction)tweetMessage:(id)sender {
if(![SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) //check if Facebook Account is linked
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to Tweet!" message:@"Please login to Twitter in your device settings." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
return;
}
//self.mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
self.mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[self.mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I found this Thing, check it out at this Place:\n %@ \n", [self someplace]]];
[self.mySLComposerSheet addImage:self.photos.firstObject];
[self presentViewController:self.mySLComposerSheet animated:YES completion:nil];
//}
[self.mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successfull";
break;
default:
break;
} //check if everything worked properly. Give out a message on the state.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
}
Questo è il modo in cui effettivamente lo uso nella mia app però. Più agevole e lascia che il controller faccia il duro lavoro.
- (IBAction)postToFacebook:(id)sender {
if(![SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
NSLog(@"log output of your choice here");
}
// Facebook may not be available but the SLComposeViewController will handle the error for us.
self.mySLComposerSheet = [[SLComposeViewController alloc] init];
self.mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[self.mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I found this Thing, check it out at SomeWhere:\n %@ \n", [self someURLString]]];
[self.mySLComposerSheet addImage:self.photos.firstObject]; //an image you could post
[self presentViewController:self.mySLComposerSheet animated:YES completion:nil];
[self.mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successfull";
break;
default:
break;
}
if (![output isEqualToString:@"Action Cancelled"]) {
// Only alert if the post was a success. Or not! Up to you.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}];
}
- (IBAction)btn_facebook:(id)sender {
SLComposeViewController *facebookcomposer =
[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookcomposer setInitialText:@"This is just a test"];
[facebookcomposer addURL:[NSURL URLWithString:@"http://www.google.com"]];
[facebookcomposer addImage:[UIImage imageNamed:@"images.jpg"]];
[self presentViewController:facebookcomposer animated:YES completion:nil];
[facebookcomposer setCompletionHandler:^(SLComposeViewControllerResult result)
{
switch (result)
{
case SLComposeViewControllerResultDone:
NSLog(@"done");
break;
case SLComposeViewControllerResultCancelled:
NSLog(@"cancelled");
break;
default:
break;
}
}];
}
- (IBAction)btn_twitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitter =
[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitter setInitialText:@"this is just a test"];
[twitter addURL:[NSURL URLWithString:@"http://www.google.com"]];
[twitter addImage:[UIImage imageNamed:@"images.jpg"]];
[self presentViewController:twitter animated:YES completion:nil];
} else {
NSLog(@"it is not configured");
}
}
- 1. Postare su Facebook Graph Api è lento
- 2. Post semplici su Facebook e Twitter iOS 5 e 6
- 3. iPhone postare immagini su Facebook Feed
- 4. Pubblica immagine su Facebook utilizzando FBSDK 4.x per iOS
- 5. Come postare un messaggio su facebook amici muro in Android
- 6. Impossibile postare su Twitter su iPhone utilizzando ShareKit
- 7. Come postare un'immagine su Pinterest?
- 8. come postare URL con Image su facebook by ShareKit
- 9. perché postare su Facebook significa "utente non ha autorizzato l'applicazione"
- 10. iOS - Twitter non funziona su iOS 5 dopo l'aggiornamento del progetto a iOS 6
- 11. @ menzioni su Facebook utilizzando Facebook Connect API
- 12. UIWebView e certificati client su iOS 6
- 13. Sistema di posizionamento interno su IOS 6
- 14. Controlla Facebook Connect Session su IOS
- 15. CIGaussianBlur e CIAffineClamp su iOS 6
- 16. Come postare/inserire dati json su ListSerializer
- 17. Come condividere post su Facebook utilizzando PHP
- 18. QLPreviewController non funziona su iOS 6
- 19. Come postare la richiesta HTTPS utilizzando Retrofit?
- 20. Problemi dell'SDBC FBConnect di Facebook su iOS
- 21. Post su Facebook come Admin
- 22. Come postare l'immagine su Twitter con Twython?
- 23. Facebook iOS 6 - ottieni informazioni utente
- 24. Condividi contenuti su Facebook dall'app iOS 5
- 25. l'integrazione di Facebook per iOS 5 e iOS 6
- 26. Condivisione con Facebook, Twitter su iOS
- 27. Condivisione di video su Facebook su iOS 8
- 28. come postare XML utilizzando RestTemplate
- 29. iOS: la foto caricata su Facebook non viene sempre caricata
- 30. Instagram iOS API per postare video
C'è bel set di tutorial qui: http://developers.facebook.com/docs/getting-started/getting-started-with-the-ios-sdk/ –
No, volevo dire utilizzando i nuovi framework su iOS 6. – jaytrixz
è possibile utilizzare il framework sociale per ulteriori dettagli visitare http://kmithi.blogspot.in/2012/10/integrating-facebook-and-twitter-in-ios.html – mithilesh