In my project, I always use SLComposeViewController to share contents with third-party apps, but now, when I update my iPhone to iOS 11 beta, this no longer works.
The SLComposeViewControllerCompletionHandler always callback SLComposeViewControllerResultCancelled.
Why is this?
I was having problems with regard to the SLComposer in iOS 11. But I just removed the line that checks and apparently the own SDK makes the validacoes to me internally.
Remove this line serves for any SLServiceType:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
So, develop your logic. In my case:
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"#myInitialTextIsHere"];
[mySLComposerSheet addURL:[NSURL URLWithString:strURL]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Sucessful");
break;
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
I hope I have helped!
iOS 11 removed access to 3rd party accounts (such as Facebook and Twitter) through the Settings App. I’m currently struggling with the same thing.
You now must integrate the functionality with the SDK from the 3rd party. Twitter has a migration page here about steps to take:-
https://dev.twitter.com/twitterkit/ios/migrate-social-framework
I’ve yet to find specific instructions about how to migrate other social networks, but it’s safe to say it will require their 3rd party SDK.
No more easy out-the-box social sharing :-(
For iOS 11 this line:
([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
is always returning NO
I replaced it with check if user has Facebook app installed with:
static NSString *const canOpenFacebookURL = #"fbauth2";
+ adding it to LSApplicationQueriesSchemes in plist
-(BOOL)isFacebookAppInstalled {
NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = canOpenFacebookURL;
components.path = #"/";
return [[UIApplication sharedApplication]
canOpenURL:components.URL];
}
And then just call SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
as usual, the same how Matheus Domingos described. But with this check at least you know that user has facebook app installed.
Related
Adding URL in Twitter and Facebook sharing in iOS application using Social framework for iOS 8.4 is not working.
Only setInitialText: method is working but not the addURL and setTile methods.
My code is as follows:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbFeed = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbFeed setInitialText:self.travelogueTitle];
[fbFeed addURL:[NSURL URLWithString:self.saveTraveloguePublishedURL]];
[fbFeed setTitle:#"My Trip's Memories"];
NSLog(#"Save published url:%#",self.saveTraveloguePublishedURL);
NSLog(#"Share published url:%#",travelogue.publishedUrl);
// [fbFeed setInitialText:[NSString stringWithFormat:#"http://mvm064/MVPWeb/ViewTravelogue?travelogueId=OB1YlsTz/gngmCUTESuqlQ=="]];
[fbFeed setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"The user cancelled.");
}
else if (result == SLComposeViewControllerResultDone) {
NSLog(#"The user posted to Facebook");
}
}];
[self presentViewController:fbFeed animated:YES completion:nil];
}}
There is no method in SLComposeViewController to setTitle. SLComposeViewController is basically subclass of UIViewController so giving you facility to set title of SLComposeViewController. It will not going to post on Facebook. For post on Facebook you have method called setInitialText.
I have tried with your code and its get uploaded successfully, you can check out in following image.
I've integrated Fabric Framework in my project, now i want to compose my image by using Twitter App installed from App Store, but twitter use SLComposeViewController UI of iOS, so i don't know what is different between using SLComposeViewController and Twitter SDK ?.
When i use Facebook SDK, sharing will use facebook app, with Twitter it not.
I use this code to compose Image.
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"just setting up my Fabric"];
[composer setImage:[UIImage imageNamed:#"fabric"]];
[composer showWithCompletion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];
I have an app which build on Xcode using Objective-C. Users can send tweet, when I try to send from my iPhone it says (Can not Send Tweet, because the connection to Twitter failed). It is working with the simulator, her is the code I use:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
NSString *tweetBody = self.currentList.tweetBody;
NSString *rawStr = [NSString stringWithFormat:#"%#", tweetBody];
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:rawStr];
[composeController addURL: [NSURL URLWithString:#"https://my app url on Apple store"]];
[self presentViewController:composeController
animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else
{
NSLog(#"post");
}
};
composeController.completionHandler =myBlock;
}
}];
I hope to find the answer with you guys.
Have you checked the Privacy settings for Twitter? It's possible that you didn't grant it permission to access your Twitter accounts. The image below shows all apps that have been granted permission to access my Twitter account,
How do I post image and text to Twitter via Twitter native app ?
Is there any Twitter api to tweet via native Twitter app in IOS programmatically ?
or , How can I post image using Social or Twitter framework via Twitter native app?
Thanks
Please Try this answer. I think this will help u
- (void)postToTwitter
{
SLComposeViewController *tweetSheet=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
// if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
// {
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[tweetSheet dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancel");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Post");
}
break;
}
};
[tweetSheet setInitialText:#"your text"];
[tweetSheet addImage:[UIImage imageNamed:#"imageToSend"]];
[tweetSheet setCompletionHandler:completionHandler];
[self presentViewController:tweetSheet animated:YES completion:nil];
//}
}
Hi for sharing information via iOS app it is possible to use native share screen.
Using this code you going to share image via different social media.
UIImage *picture = [UIImage imageNamed:#"picture"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[picture] applicationActivities:nil];
Hi i am using following code to share message using IOS6 native lib
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Good morning all"];
//[mySLComposerSheet addImage:[UIImage imageNamed:#"img1.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://www.google.com/"]];
[self.superViewController presentViewController:mySLComposerSheet animated:YES completion:nil];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output = #"";
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"ACtionCancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Successfull";
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook Message" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
}
it is successfully posted But in my facebook it is showing via IOS but i want to display my application name. I followed all steps when i am creating app id on facebook developer zone
How to change IOS to my application name?
I also tried this code http://www.developers-life.com/facebook-compose-view.html
When using SLComposeViewController you cannot change the "via" name, it will always show "iOS" as the source.
You are required to use the Facebook iOS SDK and set up your own custom compose view instead of using the native SLComposeViewController.
UPDATE
Facebook's 3.5+ SDK offers a number of great solutions, such as the Share Dialog, which uses the native Facebook and open graph.