Twitter and Facebook integration iOS 7 - ios

I am trying to implement Twitter and Facebook into my app. Therefor I am using the integrated method in iOS, which is available since iOS 6, to do this. Under iOS 6, if there is no Facebook or Twitter configured an alarm view comes up to inform the user that he has to configure an account first to use Twitter or Facebook. The alarm view gives the user the option to jump directly to the settings of Twitter or Facebook. In iOS 7, if there is no account configured, no alarm view comes up to inform the user. Seems that has been disabled under iOS 7. So I am now inform the user myself but is there a way to point the user directly to the settings like it was under iOS 6? Or do I need to change my code under iOS 7 to get the alarm back?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//inform the user that no account is configured with alarm view.
}
}

Just remove this line from your code and it will work correctly
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])

in ios 7, Try with removing this condition, it will tells user to if there is no account configured.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{ SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello a Tweet"];
[self presentViewController:tweetSheet animated:YES completion:nil];
//inform the user that no account is configured with alarm view.
}
}

Related

Launch device twitter settings from objective-c iOS 9

How can i launch the twitter settings on the Device from my app with objective-c?
I am working on an app that shares a link on twitter, i am using the SLComposeViewController and it works, but when the Twitter app is not installed and no Twitter account is configured on settings it does nothing.
I want to show an alert inviting the user to log in on twitter to be able to share the link, when the user taps on a button the app should launch the Twitter settings on the device.
I have been reading that using the url scheme like this is not allowed since iOS 5.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
I read it is only allowed to launch your app settings with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
But i have found in some apps that it actually opens the Twitter settings like this one:
screenshot of meme generator app that opens twitter settings
Do you know how to do this?
Here is the code i use for the SLComposeViewController:
- (IBAction)twitterAction:(id)sender {
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center=self.view.center;
[activityView startAnimating];
[self.view addSubview:activityView];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composerSheet setInitialText:#"text to post"];
[composerSheet addURL:[NSURL URLWithString:#"http://urltoshare.com"]];
[composerSheet addImage:[UIImage imageNamed:#"postimage.JPG"]];
[composerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[activityView stopAnimating];
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
// some code ...
break;
case SLComposeViewControllerResultDone:
[self changeSharedStatus];
NSLog(#"Post Sucessful");
// some code ...
break;
default:
break;
}
}];
[self presentViewController:composerSheet animated:YES completion:nil];
}else {
/* code to show the alert that invites the user to open settings */
}
}
Why the app that you found opens the Twitter settings,
it's because when you ask iOS to "create" a tweet, if there is no account setup in iOS, iOS will show you up this alertview asking you if you want to go in the setting for adding a twitter account to iOS.
So if you call SLComposeViewController the code is going to trigger this alertview if there is no twitter account in iOS:
SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controllerSLC setInitialText:#"text"];
[self presentViewController:controllerSLC animated:YES completion:nil];

SLComposeViewController on iOS6, trying to send image but the send button can not be enabled

I'm trying to post image and text to twitter. On iOS7,8 the following code works well. but only on iOS6, send button is disable. When I try to send only text, send button become enable. Only when I try to send image, send button is disable. I have to support iOS6,7,8. I have no idea why It dose not work on only iOS6 and image. Someone know the reason or had know the same trouble as this?
Please advise me.
We found this problem on the iPhone4s that's iOSversion is 6.1.3.
SLComposeViewController *twvc= [SLComposeViewController composeViewControllerForServiceType:type];
[twvc setInitialText:#"a"];
if([twvc addImage:[UIImage imageNamed:#"x.jpg"]]){
NSLog(#"IMAGE IS OK");
}else{
NSLog(#"IMAGE IS NG");
}
[twvc addURL:[NSURL URLWithString:#"http://rara"]];
[twvc setCompletionHandler:^(SLComposeViewControllerResult result){
// 結果判定
switch (result) {
case SLComposeViewControllerResultDone:
break;
case SLComposeViewControllerResultCancelled:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}];
[self presentViewController:twvc animated:YES completion:nil];

Is there any way to detect if a user actually pressed the Twitter/Facebook post button in app?

I am trying to give "bonus points" for users who either tweet my advertisement message or post my advertisement message on Facebook. How can I detect if...
1) The user actually pressed the post button (this way I can give them the bonus points in app)?
2) The user did not change any text in the message box (my advertisement)?
On a side note, is it possible to make the message box for these un-editable? Here is my code to actually present the message to post each:
- (IBAction)tweetButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"My advertisement message goes here."];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Twitter Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Twitter through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (IBAction)facebookPostButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My advertisement message goes here."];
[self presentViewController:controller animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Facebook Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Facebook through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
You can use compliton hander to know if he press the post button, however you can't know what the content of the post.
If you realy want to you need to implement facebook yourself than you can even check the privecy of the post.
I say this because when a app ask me to post I always do it as "Private" so no one see but I still get the "Bonus".
Apple Docs
Possible values for the result parameter of the completionHandler property.
Declaration
OBJECTIVE-C
typedef NS_ENUM (NSInteger,
SLComposeViewControllerResult ) {
SLComposeViewControllerResultCancelled,
SLComposeViewControllerResultDone
};
Constants
SLComposeViewControllerResultCancelled
The view controller is dismissed without sending the post. For example, the user selects Cancel or the account is not available.
Available in iOS 6.0 and later.
SLComposeViewControllerResultDone
The view controller is dismissed and the message is being sent in the background. This occurs when the user selects Done.
Available in iOS 6.0 and later.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/#//apple_ref/c/tdef/SLComposeViewControllerResult

Twitter Integration in Cocos2d-iPhone

I am developing a game in which i have to post scores on my Facebook and twitter a/c.
I have written this code but it not working. It's neither giving any error nor any popup for posting something .
- (void) SLComposeViewControllerButtonPressed: (id) sender{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
AppDelegate * myDelegate = (((AppDelegate*) [UIApplication sharedApplication].delegate));
NSString *string = [NSString stringWithFormat:#"Just scored %d. ", 10];
SLComposeViewController*fvc = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[fvc setInitialText:string];
[[myDelegate navController] presentViewController:fvc animated:YES completion:nil];
}
Please give me valid solution of this problem.
CCDirector is a subclass of UIViewController in iOS. So it can be used for presenting modal viewControllers.
[[CCDirector sharedDirector] presentViewController:fvc animated:YES completion:nil];
Update: Here is a DOC
#ifdef __CC_PLATFORM_IOS
#define CC_VIEWCONTROLLER UIViewController
#elif defined(__CC_PLATFORM_MAC)
#define CC_VIEWCONTROLLER NSObject
#endif
#interface CCDirector : CC_VIEWCONTROLLER

Twitter no longer working after Cocos2d 2.0 upgrade

I have a project that uses the Twitter API to Tweet the users high score. That project is written using Cocos2d v1.1 and everything is working fine. I recently started a new project using Cocos2d v2.0 and attempted to use the same code from my other project to incorporate the same Twitter functionality but the viewcontroller will not appear when the Tweet button is pressed. Below is the code I'm using...
if ([TWTweetComposeViewController canSendTweet]) // Check if twitter is setup and reachable
{
CCLOG(#"Can Tweet");
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// set initial text
NSString *theTweet = #"The message..."];
[tweetViewController setInitialText:theTweet];
// setup completion handler
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if(result == TWTweetComposeViewControllerResultDone) {
// the user finished composing a tweet
} else if(result == TWTweetComposeViewControllerResultCancelled) {
// the user cancelled composing a tweet
}
[viewController dismissViewControllerAnimated:YES completion:nil];
};
// present view controller
[[[CCDirector sharedDirector] openGLView] addSubview:viewController.view];
[viewController presentViewController:tweetViewController animated:YES completion:nil];
}
else
{
// Twitter account not configured, inform the user
NSLog(#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup");
}
I've discovered that "openGLView" is now depreciated and I have replaced it with "view". This still does not work. The method is firing though. I've included a CCLOG that return the string "Can Tweet" and that is appearing in the output window. Does anyone have any suggestions on how to get this to work. Let me know if I need to provide more information.
Thanks
Use this code in cocos2d 2.0
AppController * app = (((AppController*) [UIApplication sharedApplication].delegate));
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController setInitialText:string];
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
dispatch_async(dispatch_get_main_queue(), ^{
{
if (result == TWTweetComposeViewControllerResultDone)
{
//successful
[[NSNotificationCenter defaultCenter] postNotificationName:#"PPTweetSuccessful" object:nil];
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
//Cancelled
}
}
[app.navController dismissModalViewControllerAnimated:YES];
[tweetViewController release];
});
}];
[app.navController presentModalViewController:tweetViewController animated:YES];

Resources