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.
Related
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 have a twitter sharing view controller that opens in front of one of my view controllers. I make the twitter view like this:
if ([shareOption isEqual: #"Tweet"]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:combined];
[tweetSheet addImage:capturedScreen];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
I have this line of code to switch to my next view controller:
[self performSegueWithIdentifier: #"goBack" sender: self];
How can I call this line after the user finishes tweeting? I would also like this line to execute if the user decides to cancel their tweet.
EDIT
if ([shareOption isEqual: #"Tweet"]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:combined];
[tweetSheet addImage:capturedScreen];
iJustShared = #"YES";
[self presentViewController:tweetSheet animated:YES completion:nil];
[tweetSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[self performSegueWithIdentifier: #"goBack" sender: self];
}];
}
You need to have that line in your tweet controller, and if you want that segue to go back to the previous controller, you'll need to do dismissViewControllerAnimated:completion.
But, since you're using SLComposeViewcontroller and you are not subclassing it, you must use a handler by setting its completion handler:
[tweetSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
//actions!
}];
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/SLComposeViewController/completionHandler
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]) {
I have a button at the end of a guide that says Done!I need it to bring up Facebook posting dialogue and also segue back to the menu screen
At the moment I have it opening a Facebook posting screen, which pops up and goes back down when you click post or cancel. I would like it to return to the menu after the facebook process has completed. I have followed a guide on how segue programatically and have added the code to my current postToFacebook IBAction but it didn't work. I then tried to create it's own IBAction and link it to the button but it didnt work either.
Does anyone know how I can get it to segue after the Facebook dialogue
Heres my code for facebook posting in case you need it
- (IBAction)PostToFacebook:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"I just followed a guide on this App - Get it on the App Store http://"];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
And heres the code for the programatic segue
-(IBAction)nextView{
[self performSegueWithIdentifier:#"next" sender:self]; }
You can put all code in a single -(IBAction) and use a boolean value that changes it's value after executing facebook action.
Something like this,
- (IBAction)PostToFacebook:(id)sender {
if(valueOfBoolean==TRUE){
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"I just followed a guide on this App - Get it on the App Store http://"];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
valueOfBoolean=FALSE;
}
else{
[self performSegueWithIdentifier:#"next" sender:self];
}
}
Set default value for valueOfBoolean as TRUE in viewDidLoad method.
EDITED :
- (IBAction)facebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebook = [[SLComposeViewController alloc]init];
facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[NSString stringWithFormat:#"your string"]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result){
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
// here you can handle your seque, or your custom action what you want
break;
case SLComposeViewControllerResultDone:
// here you can handle your seque, or your custom action what you want
break;
default:
break;
}
// [self dismissViewControllerAnimated:YES completion:nil];
}];
}
else{
UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:#"No Facebook Account" message:#"There are no Facebook accounts configured. You can configure or create accounts in settings ." delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alertView show];
}
}
I hope it helps !