ios 6 - Post to Facebook in app not working on device - iphone

I have a button that brings up the Facebook ui to make a post, but it doesn't do anything on the device. It works fine in the simulator, but performs no action at all on the phone.
Not sure what I can do to figure out the problem -
Here is my ViewController.h
- (IBAction)postToFacebook:(id)sender;
ViewController.m
- (IBAction)postToFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"Posted from IOS App Test -- It works!"];
[self presentViewController:controller animated:YES completion:Nil];
}}

You code is working on simulator because isAvailableForServiceType always returns 1 in Simulator. In device you need to setup a facebook account from settings.
Or better just remove this check
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]
With this along with the post sheet an OS alert will appear to notify that account setup is required to post.

Related

UIActivityViewController in iOS 7

In my app I have added these lines of code to incorporate the functionality of uiactivityviewcontroller
UIImage *yourImage = someImg;
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:#"abcdefgh",yourImage, nil] applicationActivities:nil];
activityVC.excludedActivityTypes = #[ UIActivityTypeMessage ,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:nil];
and UIActivityViewContoller working fine, but the UI is like this: no FB icon, no Twitter icon and this is a screen-shot of an iPad:
However it is showing perfect UI in iOS 6. What might be the reason for this?
Let me tell you that your code is correct, after some test finally I could fix it, just go to Settings add Social Accounts (Facebook - Twitter - Flickr - Mail), run again your app and you will see the icons. Regards from Cancun!
Are you using the Simulator? In my experience, UIActivityViewController the UI is buggy in the simulator, but if you test on an actual device, it runs fine.
Try testing on a device.
the problem was with the device.. It was running well in iPhones

iOS SLComposeViewController - url not displaying for twitter post

I am using the SLComposeViewController to post to twitter and Facebook. I have the same code for both twitter & facebook but the URL is not showing up in the twitter post. How do I fix this?
Twitter code -
socialController = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[socialController setInitialText:#"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:#"image.jpg"]];
[socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];
Facebook code -
socialController = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialController setInitialText:#"Testing: This is the app link!"];
[socialController addImage:[UIImage imageNamed:#"image.jpg"]];
[socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
[self presentViewController:socialController animated:YES completion:nil];
SLComposeViewController shows the URL as an attachment on tweet compose view. When it is sent, URL will be appended to the end of the post. You may even add multiple URLs, they will be still shown as attachments. So this is the way it should be, there is nothing to fix.
I suggest you actually send the tweet, and check on your Twitter account wether it is really missing the URL or not (it may just be working as expected)
This is apparently not what's causing your troubles, but beware of your message length: I have found out that when the text message is too long, the Twitter API silently skips the steps where it should include the shortened URLs for the image and the URL.
According to this answer, your text should not exceed 113 characters if you use addURL twice.
i suggest to refer this link.. debug your code and there is one method
- (BOOL)addURL:(NSURL *)url that Returns a Boolean value indicating whether the URL was successfully added.
The SLComposeViewController -addURL: method returns a BOOL to indicate if the URL you are trying to attach fits in the character space remaining. Modify your code to check if that is actually returning NO:
BOOL urlOK = [socialController addURL:[NSURL URLWithString:#"http://www.google.com"]];
if(!urlOK) {
//Notify the user, truncate the message, or something else depending on your use case
}
Twitter now limits tweets to 117 characters if you include a link

Social.framework don't work on device

I want make button for share on Facebook with the social.framework. I make this:
#import <UIKit/UIKit.h>
#import <Social/Social.h>
#interface SocialSharingViewController : UIViewController
- (IBAction)postToFacebook:(id)sender;
#end
Then I add in m. File:
- (IBAction)postToFacebook:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[self presentViewController:controller animated:YES completion:Nil];
}
}
It's work perfect in emulator but when I test this on my iPhone 5 device it's doesn't work. When I click on the button postToFacebook nothing happens.
Pleas help me
The possible error is that your iphone 5 is not configured any fb account. [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] will return NO in this case
As per the documentation for the SLComposeViewController, isAvailableForServiceType "returns a Boolean value indicating whether the service is accessible and at least one account is set up... For the account to be available, the user must be logged into the social service in the device settings."
NOTE: Whenever you add a if condition, use else condition too. #codingstandard

How to open settings from our app in ios5.1? [duplicate]

Looks like iOS 5.1 has broken the standard URL encoding for navigating a user to a Preference.
For example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
Works in iOS 5.0 but not in iOS 5.1 (both device and simulator).
Has anyone found a way to replicate this functionality in iOS 5.1?
It is little tricky , i get by the removing the subviews in *TWTWeetComposeViewController*, so it shows only alert when user is not loged in and by the clicking on setting button , we can open Setting page in my app.
+ (void)setAlertForSettingPage :(id)delegate
{
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
[delegate dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[delegate presentModalViewController:tweetViewController animated:YES];
//tweetViewController.view.hidden = YES;
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
here , delegate is your viewcontroller , if you are using this method inside your viewcontroller just use self instead of delegate.
EDIT: If you get any deprecated errors, use the following iOS6 compatible code instead:
- (void)setAlertForSettingPage
{
// Set up the built-in twitter composition view controller.
SLComposeViewController *tweetViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
// Present the tweet composition view controller modally.
[self presentViewController:tweetViewController animated:YES completion:nil];
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
No I don’t know a way to replicate this functionality.
But what you can do is file a Radar requesting the restoration. Here is a radar requesting that the schemes be documented in the first place.
David Barnard has confirmed that iOS 5.1 breaks the settings apps URL schemes.
Update: iOS 8 has similar functionality for opening your app’s settings. Thanks Apple, Mike and Soto_iGhost.
The constant UIApplicationOpenSettingsURLString (UIApplication Documentation) will open the settings for your app and not, say Twitter’s settings. Not exactly the same functionality but much cleaner than before and now officially recognized.
This should be extra useful now that each app has a place in Settings for using privacy, cellular data, background app refresh and notifications.
you can do this.
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
// Manually invoke the alert view button handler
[(id <UIAlertViewDelegate>)ctrl alertView:nil
clickedButtonAtIndex:0];
}
If you look in Twitter's framework (that Twitter view controller), it has "prefs:root=TWITTER" inside, 5.1 also has this line. So probably Apple made something to disable it for other apps, like some special key in plist or method "openURL" somehow checks if it's not a system app.

iOS 6 Social framework not going to settings or no alert

I'm trying to implement the new social framework in iOS6, and have it working, except for 2 weird problems. If I've enabled the services I'm interested in (say... FaceBook), then it works fine. However, if the accounts are deleted from the settings panel (let's say FaceBook, to be consistent), then I get differing, and frustrating behaviors in the simulator and the device.
Here's the relevant code in my view controller:
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
//check to see if facebook account exists
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
}
And here's the weird behavior when firing off the above method:
In the simulator (version 6.0 (358.4) I get the dialog informing me that I haven't set up any faceBook accounts with "Settings" and "Cancel" buttons. Hitting "Settings" just dismisses the dialog, but doesn't take me to the settings panel.
On my iPhone 4s running 6.01, hitting the button that triggers the method results in... nothing. In other words, I get no dialog informing me that I have to set up a FaceBook account.
Thanks in advance for your help.
OK... Here's the fix:
Here's my new implementation, based on user1734802's helpful comment.
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
At some point I expect
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
to actually work correctly (triggering the automatic dialog, and taking you to settings), so I actually just commented it out in my code.
I had the same problem, i fixed it by removing the If statement:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
Then the view will display although there is no Facebook/Twitter account configured in the settings.
And the "No Facebook/Twitter accounts" alertView showed! And I was able to hit the "Settings" button on the alert, and it directed me to the settings (Configure Facebook/Twitter account in the settings)
This is the code I used, and it works perfectly for me:
- (IBAction)bTwitter:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:#""];
[mySLComposerSheet addImage:[UIImage imageNamed:#""]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}