Adding iOS app to Twitter accounts in settings?? - ios

I am adding some sharing in my app to allow the use to post to FaceBook and to Twitter. I decided to use the Social Sharing framework as it does exactly what I need and works well.
However I noticed that my app doesn't ask the user for permission it assumes it has permission and does a check if there is an account setup.
The problem I see here is due to this - my app doesn't appear in the Settings - > Twitter under "Allow these apps to use your account" section.
Her is the code I use when I want to share an item - user taps on a UIButton which presents a UIActionSheet with various options"
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled){
NSLog (#"Cancelled");
}else {
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler = completionBlock;
NSURL *url = [NSURL URLWithString:self.item.url];
/* Adding the text to the Tweet */
[controller setInitialText:#"Online now!"];
[controller addURL:url];
[controller addImage:self.imageView.image];
[self presentViewController:controller animated:YES completion:nil];
}
else {
[self showUserAlert:#"" message:#"Please make sure your FaceBook account has been setup on this device"
delegate:self
cancelButtonTitle:#"Okay"];
}
How do I ask for access first? And add the app to the settings part of iOS so the user can turn it on or off?

I think you don't need a permission because your app can't post without user action. User have all control.
You can check if sharing possible with canSendTweet method in TWTweetComposeViewController. Look up Xcode documentation. I'm sure Apple has something similar for Facebook.
Apple documentation

Related

Twitter addImage returns False

Here's my code:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
UIViewController* rootVC = [self getRootViewController];
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
NSLog(#"Image: %f",image.size.height);
[tweetSheet addImage:image];
NSLog([tweetSheet addImage:image] ? #"True" : #"False");
[tweetSheet setInitialText: //text
[rootVC presentViewController:tweetSheet animated:YES completion:nil];
}else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"No Twitter Account"
message: //message
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[alertView show];
}
The first log returns my image's size, so it isn't nil. The second log returns False. On an iOS 6 device, I'm unable to tap the send button. On an iOS 9 device, not only can I send it, but the image is attached successfully to the tweet. Am I not correctly logging addImage? How could it tweet the image if it wasn't added? I'm trying to fix the disabled send button on iOS 6, but now I'm worried about its functionality on iOS 9 despite tweeting successfully.
Please help me resolve this, it's my last problem before I can ship my game.
This method returns NO if image does not fit in the currently available space or if the view controller has already been presented to the user (and therefore cannot be changed). For the accepted UIImage formats, see Figure 2. Image size limits are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.
i remember a similar problem, the solution was to reformat the images (or change the dpi, dont remember now)

Detecting if Twitter account is set up on iOS 7

I've been following some tutorials on integrating Twitter into my application. Here is what I have so far:
- (IBAction)postToTweeter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
My storyboard has a button, and when a user taps that button, this is the code that gets called. However, this only works whenever they have a Twitter account setup on their iPhone first. How can I handle the case where a user has not set up a twitter account yet, and show them an alert instructing them to add a Twitter account?
SLComposeViewController has a very handy built-in mechanism, whereby it will offer to send the user to Settings if you instantiate a ComposeViewController when the user hasn't set up / logged into the social-media service in question. To test this, all you need to do is remove the conditional so your code looks like this:
- (IBAction)postToTweeter:(id)sender {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
...and you'll find that iOS will automatically pop up an alert which will take the user through to Settings.
Note that I've found that this doesn't tend to work in the simulator, so it's best to test on a device.

Simple way to add Facebook/Twitter share to app?

I'm looking for a drop in solution to add a Facebook and Twitter share button option to my app. I've googled this of course, and found shareKit but it's non-ARC so just throws lots of errors, which is of no use to me. Any other options? they need to be ARC compatible.
I want a SDK that I can drop in, throw in the App ID's and be done.
If you want simple sharing, the following can be used for Twitter and Facebook:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setInitialText:#"Your text"];
[slComposeViewController addImage:[UIImage imageNamed:#"NameOfImage"]];
[self presentViewController:slComposeViewController animated:YES completion:nil];
} else {
//Show alert or in some way handle the fact that the device does not support this feature
}
For Facebook, simply replace SLServiceTypeTwitter with SLServiceTypeFacebook. The "Social" framework must be imported :-)
You can use UIActivityViewController:
NSArray * activityItems = activityItems = #[#"title", [NSURL URLWithString:#"urlstring"]];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
References : https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html
Yes use the native iOS sharing dialog: UIActivityViewController

iPhone app freezes on presentViewController with SLComposerViewController

I am implementing sharing with Facebook and Twitter - On the simulator both of these work, but on my iPhone 4S running iOS6 the Facebook button freezes the app. The code is the same as it is for the Twitter and functions the same (it hits presentViewController, then the app just stops responding).
The code is as follows:
SLComposeViewController *mulitpartPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// Set the text of the tweet
[mulitpartPost setInitialText:[NSString stringWithFormat:#"I've had a change in weight of "]];
// Add the image to the tweet
if([[NSUserDefaults standardUserDefaults] boolForKey:#"fbProgPicShare"])
[mulitpartPost addImage:[_imgCurrent image]];
mulitpartPost.completionHandler = ^(SLComposeViewControllerResult res){
[self dismissViewControllerAnimated:YES completion:nil];
};
// Display the tweet sheet to the user
[self presentViewController:mulitpartPost animated:YES completion:nil];
isAvailableForServiceType also returns YES if I put that into the code - so I cannot think of why this would freeze when the Twitter button works on the phone. Both Twitter and FB accounts are setup.
Any help would be appreciated.
Strange Fix
It seems to work consistantly now that I do
// Display the tweet sheet to the user
if(!(multipartPost == nil))
[self presentViewController:mulitpartPost animated:YES completion:nil];
Otherwise it still freezes.

Settings button of iOS Facebook SDK 3.1 not working

I have done all steps that are explained here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/
I have tested the demo projects and fail the same as on my project. (you can test it on HelloFacebookSample project).
When you don't have any Facebook account configured, you can't share something on facebook, or upload an image etc, (the same as twitter framework). So the frameworks shows you a message that tells this:
There are no Facebook accounts configured. You can add or create a Facebook account in Settings.
You click on settings but the only thing that happends is that this dialog is hided, but the framework doesn't open the Settings tab (as work on for example on the twitter framework).
Does anyone know how to solve this problem?
Thanks in advance.
Please use SLComposeViewController class for Facebook sharing, setting button work for you.
if([SLComposeViewController class])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:text];
[controller addURL:[NSURL URLWithString:encod]];
[self presentViewController:controller animated:YES completion:Nil];
//[message release];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
NSString *output= nil;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output= #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output= #"Post Succesfull";
[self displayText:#"done"];
break;
default:
break;
}
};
controller.completionHandler =myBlock;
}
This code is working for me
Why dont u use UIActivityViewController ?
iOS 6 have the best support with UIActivityViewController
UIActivityViewController *ActivityView = [[UIActivityViewController alloc] initWithActivityItems:Items applicationActivities:nil];
Best Integration for Facebook, Twitter and sms Service

Resources