I want to provide functionality to get user sign in via twitter in my app.
I have spend 2 days in just reading the blogs , dev.twitter.com .. but i reached nowhere.
Can anyone help me .. or just tell me any open source app. thats provides this functionality..
thanks
If you develop for IOS 5 and later versions just add Twitter.framework to your target.
User uses settings screen to login and logout to twitter
#import <Twitter/Twitter.h> in your class/viewcontroller.
then call following method anywhere in your code
if ([TWTweetComposeViewController canSendTweet])
{
//yes user is logged in
}
else{
//show tweeet login prompt to user to login
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}
Also look at this tutorials:
http://www.raywenderlich.com/21558/beginning-twitter-tutorial-updated-for-ios-6
http://mobileorchard.com/ios-tutorial-twitter-integration-in-ios5/
The Social Framework (iOS6) has built-in twitter functionality that will save you some time. In iOS5 there is a (very) similar Twitter Framework.
You need to use OAuth. Read "Getting started with OAuth 2.0" by Ryan Boyd
Related
I have set up a Facebook login for my app and it works but what I don't know how to do is when you log in the app through Facebook, the app should take you to a menu screen that I have created in a view controller. Right now with Facebook login it is taking me to the log out page. Any help would be appreciated.
In my ViewController:-
- (void)viewDidLoad{
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.readPermissions = # [#"public_profile", #"email", #"user_friends"];
[self.view addSubview:loginButton];
if ([FBSDKAccessToken currentAccessToken]) {
[self performSegueWithIdentifier:#"Cell" sender:self];
}
}
I am checking if the user is logged in, and if yes perform the segue nothing happens.
When your facebook request complete the authentication process, the FB button is automatically turned into "log-out" mode since that is the next option for the user. To transition to a new view controller you can call a segue in the delegate method as shown below. This method will be called at the end of the FB credentialing, if you have subscribed to the delegate FBSDKLoginButtonDelegate:
- (void)loginButton:(FBSDKLoginButton*)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult*)result
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
}
I am trying to set initial text to SLComposeViewController in iOS 9 , but it is displaying blank in dialog.
Here is my code.
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *initialText = #"Tesing text issue.";
if (initialText != Nil)
{
[composeController setInitialText:initialText];
}
dispatch_async(dispatch_get_main_queue(), ^
{
//show progress hud here
[self presentViewController:composeController animated:YES completion:nil];
});
I have aslo check this in another sharing app, they have also same issue. Can anybody have any workaround here?
Facebook has deprecated the api to set initial text programmatically while sharing. Below are the references:
https://developers.facebook.com/docs/apps/review/prefill
https://developers.facebook.com/docs/sharing/ios
Hope this helps.
You can set the initial text using graph API and custom share dialogue.
https://developers.facebook.com/docs/sharing/opengraph/ios#custom
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
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.
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