i m using AddThis SDK for facebook,twitter and Email share, facebook and Email is nicely working while Twitter is giving error while conecting from my Iphone. it nice work from my simulator but from iphone twitter not connecting and just display a message in console"Error!" code: [AddThisSDK setTwitterViaText:#"QuotesApp"];
[AddThisSDK shareURL:#"http://HazratAliQuotes.com"
withService:#"twitter" title:string description:#"QuotesApp"];
Try this link to implement Twitter in your application for previous version of iOS
The Previos API of twitter is known as MGTTwitter
For AddThis:
To use Twitter OAuth-enabled sharing, you'll need to tell the library to do so, and then configure your Twitter consumer key, consumer secret, and callback URL.
[AddThisSDK setTwitterAuthenticationMode:ATTwitterAuthenticationTypeOAuth];
[AddThisSDK setTwitterConsumerKey:#"yourconsumerkey"];
[AddThisSDK setTwitterConsumerSecret:#"yourconsumersecret"];
[AddThisSDK setTwitterCallBackURL:#"yourcallbackurl"];
Below is the new answer added.
Remove the line [AddThisSDK setTwitterViaText:#"QuotesApp"];
Add the line [AddThisSDK setTwitterAuthenticationMode:ATTwitterAuthenticationTypeOAuth];
and on twitter button pressed create a selector and add the following code as
[AddThisSDK shareURL:#"http://www.addthis.com"
withService:#"twitter"
title:#"AddThis - The #1 Bookmarking & Sharing Service"
description:#"AddThis is a free way to boost traffic back to your site by making it easier for visitors to share your content."];
This is optional answer for you. In IOS 5 there is framework Tweeter.Framework. add this Framework and import, i use this for uploading a image(as a link) and message. may be it's helpful for you.:)
import "Twitter/Twitter.h"
and on Button Click..
- (void)postImageOnTweeterWall
{
if (imageView.image)
{
NSLog(#"tweetbutton pressed called");
// Create the view controller
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
// Optional: set an image, url and initial text
[twitter addImage:[UIImage imageNamed:#"img1.jpeg"]];
// [twitter addURL:[NSURL URLWithString:[NSString stringWithString:#"http://MobileDeveloperTips.com/"]]];
[twitter setInitialText:#"Tweet from iOS 5 app using the Twitter framework."];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}
else
{ UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:#"Tweeter" message:#"Select photo to Upload"
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[alertView show];
}
}
Related
How to avoid duplicate games entry in chart boost more games section?
Here is my code, and added more than one campaign to fill entries….is there any way to restrict duplicate?
-(void)initChartboost
{
Chartboost *cb = [Chartboost sharedChartboost];
cb.delegate = self;
//change here
cb.appId = CHARTBOOST_APPID;
cb.appSignature = CHARTBOOST_APPSIGNATURE;
[cb startSession];
[cb cacheMoreApps];
}
-(void)showMoreGames
{
if([self connected])
{
Chartboost *cb = [Chartboost sharedChartboost];
[cb showMoreApps];
}
else
{
UIAlertView* alert= [[[UIAlertView alloc] initWithTitle:#"No Internet Connection!" message: #"Checkout your internet connectivity!"
delegate: NULL cancelButtonTitle: #"OK" otherButtonTitles: NULL] autorelease];
[alert show];
}
}
This was a temporary glitch that Chartboost was experiencing a few days ago. It's been resolved, so you don't have to do anything to fix it!
It is fine to add the same campaign in multiple slots on the more apps page, so please feel free to set it up this way for convenience!
Full disclosure: I work for Chartboost.
Try using the same campaign in the More Apps page.
I wanted to share a Twitter feed on the Twitter wall which contains an image and some text. I want support from iOS 4.3 to iOS 6.0.1. Is sharing possible in the background without a send/share button? How do I implement it?
The API call that you need to send is:
https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
Before making that call, of course, you will need to authenticate with Twitter via xAuth/OAuth. Unless you get special permission from Twitter to do otherwise, it looks like you will need to use OAuth,
https://dev.twitter.com/docs/oauth/xauth
To background the request, it will likely make sense to use Grand Central Dispatch --that is unless you have a lot of different Twitter requests to send. In that case, I would instead opt for an NSOperationQueue where maxConcurrentOperationCount = 1. See the following:
http://www.fieryrobot.com/blog/2010/06/27/a-simple-job-queue-with-grand-central-dispatch/
http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
Nevertheless, because OAuth is such a pain, it will likely make sense to use a third party library. I've never used it before, but here is an example using MGTwitterEngine:
Twitter's statuses/update_with_media on iOS returns 500 error
If you were able to limit use to iOS 5+, then I would highly recommend using the SLRequest object. The advantage of this approach is that you integrate with the iOS users account directly, so they don't have to authenticate through a UIWebView or something cheesy.
To do so, you would simply plug in the appropriate Twitter API url in the following function requestForServiceType:requestMethod:URL:parameters: and obtain your SLRequest object. Then assign the appropriate Twitter ACAccount obtained from the ACAccountStore using requestAccessToAccountsWithType:options:completion:. Finally make your call to performRequestWithHandler, which would then perform your request asynchronously.
The following code will not post in background but it can post across ios versions...
You can use condition for ios versions like below code.This is working code I have implemented and it is working on both ios 5 and 6. Please check in ios 4 to confirm.I think it should work.
#import "Twitter/Twitter.h"
#import "Social/Social.h"
-(IBAction)tweetPost:(id)sender
{
if ([self isSocialAvailable])
{
SLComposeViewController *tweetComposer=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewControllerCompletionHandler __block completionHandler=
^(SLComposeViewControllerResult result){
[tweetComposer dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Sent"
message:nil
delegate:nil
cancelButtonTitle:#"Dismiss"
otherButtonTitles: nil];
[alert show];
}
break;
}};
NSString*message = #"posting to twitter test ios 6";
[tweetComposer setInitialText:message];
[tweetComposer addImage:[UIImage imageNamed:#"2.jpg"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=GoZ2Be2zLq8"]];
[tweetComposer setCompletionHandler:completionHandler];
[self presentViewController:tweetComposer animated:YES completion:nil];
}
}
else
{
TWTweetComposeViewController *twitter= [[TWTweetComposeViewController alloc] init];
[twitter addImage:[UIImage imageNamed:#"2.jpg"]];
[twitter addURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=GoZ2Be2zLq8"]];
[twitter setInitialText:#"Tweet from iOS 5 app using the Twitter framework."];
[self presentModalViewController:twitter animated:YES];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
};
}
}
-(BOOL)isSocialAvailable {
return NSClassFromString(#"SLComposeViewController") != nil;
}
You need to include three frameworks named social,adSupport and Accounts.Check which one not needed with twitter feed post.
Hope ,this will help you.
Yes, but you'll need find some 1.1 API wrapper (thing which generates API requests, singns them etc) for you and authoriser (MGTWitter engine works fine). I have a working solution for sharing (text only) and getting user info for iOS 4+.
And about background part - that depends on how you implement that (i.e. notifications or continious background execution or gps callbacs etc...).
I am testing this piece of code but when I run it, it does not trigger the UIAlertView. When the code hits If (ongoingGame = YES) and NSLog it jumps directly to the 'otherButtonTitles:nil' without executing the UIAlertView.
Can someone please explain to me why it does not trigger it?
-(IBAction)continueGame_button:(id)sender {
//=====CHECK IF THERE IS AN ON-GOING GAME, IF SO CONTINUE=====//
AccessCurrentGameData *isThereAnOngoingGameFunction = [AccessCurrentGameData new];
BOOL ongoingGame = [isThereAnOngoingGameFunction checkIfGameOngoing];
[isThereAnOngoingGameFunction release];
NSLog(#"+ + +continueGame_button+ + +");
NSLog(#"ongoingGame = %#\n", (ongoingGame ? #"YES" : #"NO"));
if (ongoingGame == YES) {
NSLog(#"++++++++++++++++++");
NSLog(#"++++++++++++++++++");
NSLog(#"++++++++++++++++++");
NSLog(#"++++++++++++++++++");
NSLog(#"++++++++++++++++++");
//
UIAlertView *continueGame = [[UIAlertView alloc] initWithTitle:#"Fortsätta spel"
message:#"Det finns ett aktivt spel, klicka Spela eller Tillbaka"
delegate:self
cancelButtonTitle:#"Tillbaka"
otherButtonTitles:nil];
[continueGame show];
[continueGame release];
}
exit(0);
}
You are assigning onGoingGame to YES, not comparing it to YES. Use == instead of =.
Your alert code is just fine I use that form (three lines - init, show, release) all of the time to do alerts.
I suggest that the exit(0) is the root of the problem. If you want to exit after the user closes the alert, you should assign a delegate which will close the app when the user taps on the close button. Use your code, but remove the exit(0). Then implement the UIAlertViewDelegate as follows:
-(IBAction)continueGame_button:(id)sender {
//=====CHECK IF THERE IS AN ON-GOING GAME, IF SO CONTINUE=====//
AccessCurrentGameData *isThereAnOngoingGameFunction = [AccessCurrentGameData new];
BOOL ongoingGame = [isThereAnOngoingGameFunction checkIfGameOngoing];
[isThereAnOngoingGameFunction release];
NSLog(#"+ + +continueGame_button+ + +");
NSLog(#"ongoingGame = %#\n", (ongoingGame ? #"YES" : #"NO"));
if (ongoingGame == YES) {
NSLog(#"+++++++++ ONGOING GAME +++++++++");
//
UIAlertView *continueGame = [[UIAlertView alloc] initWithTitle:#"Fortsätta spel"
message:#"Det finns ett aktivt spel, klicka Spela eller Tillbaka"
delegate:self
cancelButtonTitle:#"Tillbaka"
otherButtonTitles:nil];
[continueGame show];
[continueGame release];
}
}
- (void) alertViewCancel:(UIAlertView *)alertView{
//If you have other alerts, you may want to check the title of the alert to
//make sure that you only exit when THIS alert is dismissed
exit(0);
}
Dont' forget to add the <UIAlertViewDelegate> code to your header (.h) file.
You can also use - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex, if you want multiple buttons, with one of them being a specific "Quit" button.
Please note that Apple discourages using exit() in apps that are released to the App Store, and using it might get your app rejected.
You can try this line instead.
[[[[UIAlertView alloc] initWithTitle:#"this is my message" message:nil delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil] autorelease] show];
Also, I believe Apple does not advice using exit() within your application. They always want the user to use the "Home" button to exit an app. The exit() call is a hard exit and this might be the reason you are not seeing the Alert.
You should not release it immediately. And you exit the app even before the alert view gets a chance to display itself. :)
Your code will continue to run even when the alert view is visible.
Fixage
Remove the exit call
Don't release the alertview. Release it in it's owner's dealloc method.
Make the alert view an instance variable and add a retain property to it.
Initialize the alertview in its getter if it's not yet available.
Set it's attributes in the IBAction and show it.
Add the appropriate delegate methods.
If I wasn't writing this answer on an iPod touch I'd post some example code. You can find lots of such code with Google.
Also, if your app isn't English-only you should always use localization provided by Foundation. Otherwise you can get English text with default error messages and other UI elements.
I have the following function to display error messages to user. But it does not seem to show the complete message. It will display upto certain characters followed by ....
How can I make it show the entire message?
(void) showAlert:(NSString*)title forMessage:(NSString*) body
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:body delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
There is a way.
When you present your alert, you can just implement this method:
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y -50
,alertView.frame.size.width, 300);
}
Adjust the height to fit your need. It will look something like this:
If you need to move the button around, you can just add new lines (\n) to your message, and it will move the button down.
As mentioned by sudo rm -rf, UIAlertView has a limit.
You can try creating your own "alert" that doesn't clip by creating a view controller and showing it using presentModalViewController:animated:.
i implement FBConnect for my app via UIActionSheet with 2buttons .
my buttons are "Share On Facebook" and "Log out from facebook" . so i want when user click on share on facebook button FBLoginDialog shows and user log in to facebook with his account and then show FBStreamDial appears and user share something on his wall . and never show FBLoginDialog again . it means just one time . and when user going to log out that method repeat again .
How can mange it ?
if i use this method : 2 method appear together !
-(void)actionSheet:(UIActionSheet *)menu didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
///SHOW LOGIN WINDOW
NSLog(#"asdasda");
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
///SHOW FBStreamDialog
FBStreamDialog* dialog2 = [[[FBStreamDialog alloc] init] autorelease];
dialog2.delegate = self;
dialog2.userMessagePrompt = #"Share Ghazals on your wall";
dialog2.attachment = #"{\"name\":\"Hafez Application for iPhone\","
"\"href\":\"http://itunes.apple.com/us/app/divan-of-hafez/id340865571?mt=8?tab=iphone\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"http://momeks.com/images/fb.png\","
"\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],"
"\"properties\":{\"another link\":{\"text\":\"Hafez App HomePage\",\"href\":\"http://www.momeks.com/hafez\"}}}";
//replace this with a friends UID
//dialog2.targetId = #"999999";
[dialog2 show];
break;
case 2:
[session logout];
break;
}
}
The FBDialog's show method is asynchronous, meaning it returns before it completes whatever it is doing (in this case displaying a window).
You need to implement the delegate methods for responding to facebook dialog messages.
In the delegate methods you can outline the flow of your application.
Currently, your code show's the login dialog window, which returns instantly, and then proceeds on to show another dialog. You should only show the second dialog after the user has logged in, which you can determing using the FBSession delegate methods.