I have set my base SDK to 6.0 and my Deployment Target to 6.0.
When I build, I get the following error.
'TWTweetComposeViewController' is deprecated: first deprecated in iOS 6.0
If I drop my Deployment Target down to 5.1 it compiles without error. Since TWTweetComposeViewController is "Available in iOS 5.0 and later.", this seems opposite to what I was expecting.
I would just leave it like that but I am also using Social/Social.h which is only available in 6.0 and up and will be error prone for the 5.1 users.
This is the problematic line of code:
if ([TWTweetComposeViewController canSendTweet]){
Racking my brain on this. I'm hoping it is just some obscure setting I have missed.
Thanks in advance.
TWTweetComposeViewController is deprecated, because for iOS 6.0 there is a new framework to handle all social interactions called Social.framework. Inside there you can find similar functionality to post tweets via SLComposeViewController.
to solve your problem with iOS6 you have to options depending on what you support:
Support iOS6 and above: Just use SLComposeViewController. Link framework Social.framework and done with it.
Support iOS 5.x and above: Needs more work. First need to check if the SLComposeViewController exists (so you are in iOS 6.0), and then use it and present it, otherwise use the TWTweetComposeViewController for older iOS. Also you would need to link framework Social.framework as optional.
As a side note, if you support iOS 6 only, you can use same controller to post to facebook for free, so consider using facebook integration too.
Instead of TWTweetComposeViewController use SLComposeViewController which is include in Social Framework
- (IBAction)SendTweet:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#" THIS IS AN EXAMPLE",mySLComposerSheet.serviceType]];
[mySLComposerSheet addImage:[UIImage imageNamed:#"image.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://www.StackOverflow.com/"]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(#"dfsdf");
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"ACtionCancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Successfull";
[self dismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter Message" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
}
Related
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)
I'm trying to implement the native iOS twitter account to unity. I found a code which uses the native social accounts via Xcode, and so I'm trying to make it communicate to unity but I get this error: "Use of undeclared identifier 'self'"
Here's my code:
extern "C"
{
void _PushTwitter(const char * messageTweet)
{
//Check Twitter accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
//This is setting the initial text for our share card.
[tweetSheet setInitialText:[NSString stringWithUTF8String:messageTweet]];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is running the latest iOS version" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
}
}
}
I get the error on the [self presentViewController...] part.
This was the original code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//Each button title we gave to our action sheet is given a tag starting with 0.
if (buttonIndex == 0) {
//Check Twitter accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
//This is setting the initial text for our share card.
[tweetSheet setInitialText:#"veasoftware.com made it easy to intergate Twitter with iOS 6! :D "];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is using iOS6." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
}
Any help will be greatly appreciated.
EDIT/SOLUTION: For anybody interested, I've found a much easier integration on this article (probably the only one out there): http://www.theappguruz.com/unity/share-image-and-text-on-twitter-in-ios-using-native-code/ Works like a charm. I'm running iOS 8, Unity 5, and the latest version of Xcode.
The code that you found is probably part of an objective-c class, where self is defined and it points to the current object.
The code that you wrote doesn't seem to be a method of a class, but a global function, which means it doesn't have an object attached.
You should add the code you found to one of the classes Unity defines for you, maybe inside UnityAppController.mm
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've created an extension, in fact a Today Widget, using Xcode 6 and run it on my iOS 8 beta device (I am a registered iOS developer).
However, being new to development, I've encountered this issue with the SLComposeViewController being 'stuck' inside its view (shown below), deeming the user to be unable to interact with it and not be able to consequently post a tweet.
Is there any way to fix this and bring the SLComposeViewController to the front, in front of the Notification Centre pane? Any help would be appreciated.
Edit: (yay, fixed that "Hello World" text)
2nd Edit: Here's my SLComposeViewController code:
- (IBAction)TwitterShare:(id)sender; {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *twitterAlert = [[UIAlertView alloc] initWithTitle:#"Uh oh!" message:#"Ensure you have setup a valid Twitter account and/or you have allowed access for Twitter in this application." delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[twitterAlert show];
twitterAlert = nil;
}
}
According to Apple's documentation SLComposeViewController is not allowed to be shown in NC. They want anything that requires keyboard entry to happen in-app.
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