I need to share the URL to Facebook from my app, and I am using SLComposeViewController for same. Here is the code I am using :-
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookController setInitialText:text];
[facebookController addURL:url];
[facebookController addImage:image];
[controller presentViewController:facebookController animated:YES completion:nil];
}
Here is the URL, I am using :-
http://www.erosnow.com/#!/movie/watch/1004607/ferrari-ki-sawaari/6095229/ferrari-ki-sawaari
The problem is, it doesn't show link preview. But when I copy paste the URL in Facebook "Whats your mind" segment, it do show the link preview. Any help
Related
The Facebook sheet appears but contains no text. I am using XCode 6.3.1 and iOS 8.3 on an iPhone 6. Thank you in advance.
My code is
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:myStringObject];
[self presentViewController:controller animated:YES completion:nil];
I am trying to post on Twitter from my app, but I keep on getting the following error in the log
LaunchServices: invalidationHandler called
Below is my method for posting on Twitter. This method is in a TwitterViewController class which inherits for UIViewController
-(void)tweetHighscore {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Tweeting from my own app! :)"];
[self presentViewController:tweetSheet animated:YES completion:nil];
CCLOG(#"it's working okay");
}
}
EDIT:
I set a breakpoint and it seems like presentViewController:animated:completion: is causing the invalidationHandler.
I've search but didn't find a solution to upload screenshot to Facebook on iOS
In cocos2d-x, gamescene.cpp :
void GameScene::takeScreenshot()
{
SoundManager::getInstance()->playSound("sound2.mp3");
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height);
texture->setPosition(ccp(size.width/2, size.height/2));
texture->begin();
CCDirector::sharedDirector()->getRunningScene()->visit();
texture->end();
texture->saveToFile("screenshot.png", kCCImageFormatPNG);
Link::postToFacebook();
}
in Link:postToFacebook function :
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[controller addURL:[NSURL URLWithString:#"http://www.jinibot.com"]];
// [controller addImage:image];
[controller addImage:[UIImage imageNamed:#"screenshot.png"]];
[controller dismissViewControllerAnimated:YES completion:nil];
//add as many images as you want
// [controller presentViewController:mail animated:YES completion:nil];
}
but it doesn't work.
Help me please. Thank you !
Problem with your code is
[controller addImage:[UIImage imageNamed:#"screenshot.png"]];
This method
texture->saveToFile("screenshot.png", kCCImageFormatPNG);
saves image in Documents Directory, but here you are using image as bundle image which can not be retrieved.
So create UIImage Object from NSDocuments directory path.
The code will work fine. :)
I implemented the Social framework in my app to post on facebook. It works fine.
But if there is no account in settings, then the Defalut alert is not come in IOS 7.
In IOS 6, it will come as follow.
Is this default Problem in ios 7?
My code is as follow:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[controller addURL:[NSURL URLWithString:#"http://www.appcoda.com"]];
[controller addImage:[UIImage imageNamed:#"iconTemp.png"]];
[self presentViewController:controller animated:YES completion:nil];
}
To make it work in iOS 7, just remove the following line from your code and it will work fine.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
In my app i'm using SLComposeViewController to send tweets. I'm also calling its method addURL: like this:
[tweetSheet addURL:[NSURL URLWithString:#"http://itunes.com/apps/MyAppName"]];
and it works fine in iOS 6, but in iOS 7 it opens iTunesStore right after being presented on the screen. How do i fix it?
UPDATE:
if ([SLComposeViewController isAvailableForServiceType:network])
{
AppController *appController = (AppController *)[[UIApplication sharedApplication] delegate];
MyNavigationController *navController = appController.navController;
UIViewController *currentController = [[navController viewControllers] lastObject];
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:network];
[tweetSheet setInitialText:text];
[tweetSheet addImage:[UIImage imageNamed:temp_character]];
[tweetSheet addURL:[NSURL URLWithString:#"http://itunes.com/apps/MyAppName"]];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){
[currentController dismissViewControllerAnimated:YES completion:nil];
if (result == SLComposeViewControllerResultDone)
[[NSNotificationCenter defaultCenter] postNotificationName:HC_TWEET_SENT_NOTIFICATION object:nil];
};
[currentController presentViewController:tweetSheet animated:YES completion:nil];
}
Your custom socialIntegration class has a bug in it. It only returns a SLComposeViewController if Facebook is available on the device. If it isn't, it returns nothing.
However, you don't test for this when you actually call it:
SLComposeViewController * faceSheet=[self.socialIntegration showFacebook:#"text" andImage:nil andLink:#"link" andView:self];
dispatch_sync(dispatch_get_main_queue(), ^{
//[self netConnectionTrue:cell Connected:answer];
//[tempAlertView show];
[self presentViewController:faceSheet animated:YES completion:NO];
});
...you're not checking to see if faceSheet is nil. So if there's no Facebook account you call presentViewController with a nil object, which triggers the error you're seeing.
The reason you are seeing this on iOS 7 is your linked FB accounts probably got reset, but it was probably a source of crashes for your users on iOS 6 as well.