I know how to tweet a message using the standard iOS 5 twitter framework (using the code bellow). I do not know:
a) If it is possible to send a tweet to a specific recipient (myself). I would like to do this as a "Contact Us" feature in my app so the user can message me.
b) If there is a way to make the user follow me on Twitter.
Thanks in advance!
-(IBAction)twitter:(id)sender {
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:
#"About my app"];
[self presentModalViewController:tweetSheet animated:YES];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"No Internet Connection"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}}
a, send a reply:
[tweetSheet setInitialText:
#"#pantelisproios About my app"];
b, follow by sending a tweet:
[tweetSheet setInitialText:
#"follow pantelisproios"];
You can also use TWRequest if you want to use the twitter API directly.
Related
As twitter framework is added in ios5.0 I am using its class TWTweetComposeViewController
if([TWTweetComposeViewController canSendTweet])
{
NSLog(#"can send tweet");
}
else{
NSString *message = #"The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don't have a Twitter account associated with this device.";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Oops" message:message delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alertView show];
}
On this step I need to show user the login page of twitter.For that I am confused if i should redirect user to settings to login to user?
And if yes this code is not working
NSURL *twitterURL = [NSURL URLWithString:#"prefs:root=TWITTER"];
[[UIApplication sharedApplication] openURL:twitterURL];
Also I have read some where that this will not work in ios6. So what should i do to just make user login for a moment and not send tweet directly. Right now i just want to make user login.
I also refer to this question It is working with ios6 well but in that case how do i handle for ios5.1 ?
Any help will be appreciated....
I figured it out with below conditional coding..
I got only this way. If anyone have any other way please suggest me.
if (SYSTEM_VERSION_LESS_THAN(#"6.0")) {
if(SYSTEM_VERSION_EQUAL_TO(#"5.0"))
{
NSURL *twitterURL = [NSURL URLWithString:#"prefs:root=TWITTER"];
[[UIApplication sharedApplication] openURL:twitterURL];
}else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"No_Tw", nil) message:NSLocalizedString(#"No_TW_Ac", nil) delegate:nil cancelButtonTitle:NSLocalizedString(#"Button_Ok", nil) otherButtonTitles:nil, nil];
[alertView show];
}
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0")) {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.view.hidden=TRUE;
[self presentViewController:tweetSheet animated:NO completion:^{
[tweetSheet.view endEditing:YES];
}];
}
If iOS is 5.0 then it will redirect to login of Twitter otherwise it will show alert to user to go to settings and do login. And for for iOS 6.0 and larger SLComposeViewController is working fine.
I am very new to iOS development.I am making an application in which i required to integrate twitter and Facebook for wall posting.
I have done all the required coding for this and on simulator it is working fine but not on device.
one more question as the coding for Facebook integration i have copied it from other "demo" application.So what else we need to change in it to make it for my own application.Because when i see my update done by my app on Facebook wall, "demo" app name comes there with the post.
Please guide me !!Thanking you in Advance!!
Facebook
It seems you have jumped to coding part before reading the documentation. Before integrating facebook sdk and writing your code, you need create a new app section in facebook developer console, get an Facebook app id. You need to use that app id in your project, not the app id shipped with facebook demo application.
Documentation explains the process fully, no need to rewrite it here. Make sure you read it to the end.
Twitter
I am not sure if you are having problem in twitter also (question is unclear on that). If yes, you should tell how you are connecting to twitter. But generally, from the tone of your questions, it seems you haven't read the documentation, on creating an app section in respective developer console, and getting app id.
I don't know how much integration you need or if your willing to require iOS 6 but in iOS 6 it is SO MUCH easier to integrate Facebook and Twitter.
This is all the code:
In the header file:
#import "Social/Social.h"
In the main file:
//Twitter
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Done!");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:#"Status Text"];
[self presentViewController:controller animated:YES completion:Nil];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now. You must be online and signed into at least one Twitter account." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
//Facebook
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Done!");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:#""];
[self presentViewController:controller animated:YES completion:Nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook Error" message:#"Either you are not logged into Facebook or your Facebook username and password are incorrect." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
You Can use Share kit framework, http://getsharekit.com
As per integrating twitter in your application.Try this code
at self.fullimage write any url of image.
Call buildTweetSheet method to post to twitter.
import Twitter.framework
import
#property(nonatomic,strong) TWTweetComposeViewController *_tweetSheet;
#synthesize _tweetSheet;
-(void)buildTweetSheet
{
NSLog(#"buildTweetSheet");
_tweetSheet = [[TWTweetComposeViewController alloc] init];
UIImage *eimage=UIImage *eimage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.fullimage]]];
[_tweetSheet setInitialText:#""];
[_tweetSheet addImage:eimage];
[_tweetSheet setInitialText:#""];
[self presentModalViewController:_tweetSheet animated:YES];
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result)
{
if(result == TWTweetComposeViewControllerResultDone) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Done" message:#"Image Posted Successfully" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Failed" message:#"Image Posted Failed" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
[self dismissModalViewControllerAnimated:YES];
};
[_tweetSheet setCompletionHandler:completionHandler];
}
I am making an application where I want to send an email using smtp server.
It's working fine but if user does not provide the correct gmail account details such as (email id and password) email is not send.
What I want to do is I want to access user gmail account details from setting tab of the iPhone into my app?
Is it possible to do retrieve the gmail account detail into the app?
Please help me out with this.
Following is my code:
-(IBAction)sendemail
{
SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
//testMsg.fromEmail = #"Lexi mobile";//nimit51parekh#gmail.com
testMsg.fromEmail = soundOn;
NSLog(#"str_Uname=%#",testMsg.fromEmail);
//str_info = [str_info stringByReplacingOccurrencesOfString:#"," withString:#""];
testMsg.toEmail = [string_emailinfo objectAtIndex:0];
NSLog(#"autoemail=%#",testMsg.toEmail);
testMsg.relayHost = #"smtp.gmail.com";
testMsg.requiresAuth = YES;
testMsg.login = soundOn;
NSLog(#"autoelogin=%#",testMsg.login);
testMsg.pass = vibrateOn;
NSLog(#"autopass=%#",testMsg.pass);
testMsg.subject = #"Photo Sharing";
testMsg.wantsSecure = YES;
NSURL *url = [[NSURL alloc]initWithString:#"http://itunes.apple.com/us/app/umix-radio/id467041430?mt=8"];
NSString *msg2 = [NSString stringWithFormat:#"<html><b>DOWNLOAD NOW</b>  </html>",url];
NSString *sendmsg=[[NSString alloc]initWithFormat:#"%#",msg2];
NSLog(#"automsg=%#",sendmsg);
testMsg.delegate = self;
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
sendmsg,kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];
[testMsg send];
// [self DeleteRowAfterSending];
//[self performSelector:#selector(DeleteRowAfterSending) withObject:nil afterDelay:5.0];
}
-(void)messageSent:(SKPSMTPMessage *)message
{
[message release];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Success" message:#"Your email is sent successfully" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
NSLog(#"delegate - message sent");
}
-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
[message release];
// open an alert with just an OK button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Fail" message:#"Message sending failure" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
NSLog(#"delegate - error(%d): %#", [error code], [error localizedDescription]);
}
What i want to do is i want to access user gamil account details from
setting tab of the iPhone into my app? is it possible to do retrive
the gamil account detail into the app?
No, and with good reason: that functionality would allow any developer access to anyone's e-mail account.
That would be a massive security hole.
Much like it is with Location Services, you're just going to have to ask the user to enter their e-mail address and password. And hope they want to trust your app with that kind of personal information. (Assuming Apple approves your app at all.)
Let the user give your app authorization from Google. check the oauth autorization with google api at their developers site?
https://developers.google.com/accounts/docs/OAuth2
As usual the user signs in with his account through google api and returns back to you an access_token to get information back from his account including his email which you need.
Looking for some help again...
I've currently got 2 sections of my app that need internet connection, 1 is a photo gallery through Flickr and the other a Twitter Feed, I was wondering if this is the correct code for the UIAlertView... I can get it working from a button but thats all!
{
-(void)didTap_roundedRectButton1:(id)sender forEvent:(UIEvent *)event {
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.title = #"You are not connected to the Internet!";
alertView.message = #"Please check your connection and try again...";
[alertView addButtonWithTitle:#"Ok"];
[alertView show];
[alertView release];
}
i think you need to use this example as i have used it to check is there any network is available and device is connected to any one of the network it is alos available on the apple's developer example site
example link is this
You should try this:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"You are not connected to the Internet!"
message:#"Please check your connection and try again..."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertView show];
[alertView release];
and can you post the code how do you create the UIButton?
i am creating a music application in which i am integrating twitter in my application
When a user clicks on particular song and then he click on the twitter tab the login page of twitter should be displayed. after entering the username and password he should be directed to the page where he can enter his comment and then post it.the problem is that when i click on twitter tab the login page is diplayed but when i enter he username and password and click on submit it does not redirect me to the page where i can post my comment. Here is my code:
(IBAction) Submit: (id) sender
{
// g=text3.text.integerValue;
u=text1.text;
p=text2.text;
int flag;
NSLog(#"Username,%d",u);
//if((u!=#"") || (p!=#""))
//if((text1.text.length >= 20 && range.length !=0) ||(text2.text.length >= 8 && range.length!=0))
if([text1.text length] != 0 || [text2.text length]!=0)
{
TwitterRequest * t = [[TwitterRequest alloc] init];
t.username =[NSString stringWithFormat: #"%#",u];
//NSString *username=[NSString stringWithFormat:#"%d",u];
t.password= [NSString stringWithFormat: #"%#",p];
//NSLog(#"Password,%d",p);
//#"ajeetyaday";
//t.username= #"ajeetyaday";
//t.password = #"gopalpur";
//NSString *name1 =[NSString stringWithFormat:#"%d",g]
//twitterMessageText.text=#" hi i am ajeet";
//[twitterMessageText resignFirstResponder];
loadingActionSheet = [[UIActionSheet alloc] initWithTitle:#"Posting To Twitter..." delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[loadingActionSheet showInView:self.view];
[t statuses_update:twitterMessageText.text delegate:self requestSelector:#selector(status_updateCallback:)];
//[TwitterRequest statuses_update:twitterMessageText.text delegate:self requestSelector:#selector(status_updateCallback:)];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Clicked on Submit" message:#"Please inter Username and Password" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
I think u r in wrong way!!
U simply store user name and password in a global variable,and push to posting page
(IBAction) Submit: (id) sender
{
user_name=uname.text;
password=password.text;
Twitter *Controller = [[Twitter alloc] init];
[self.navigationController pushViewController:Controller animated:YES];
[Controller release];
}