Reputation: 14370
i am using Facebook & Twitter sharing in my app , after upgrade xCode to 9.0.1 Swift 4, both are not working , the method saying i have no FB or Tw account on my device but they're already there and was working fine with Swift 3.
Log :
2017-10-25 09:53:41.619676+0300 jack[2428:926750] [core] isAvailableForServiceType: for com.apple.social.facebook returning NO
and here is the Code :
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook)
{
let shareText = "xxx"
let facebookShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
//facebookShare.add(imageView.image!)
facebookShare.add(URL(string:self.track.share_url))
facebookShare.setInitialText(shareText)
self.present(facebookShare, animated: true, completion: nil)
}
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter)
{
let shareText = "xxx"
let twitterSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
twitterSheet.add(URL(string : self.track.share_url))
twitterSheet.setInitialText( shareText )
self.present(twitterSheet, animated: true, completion: nil)
}
Upvotes: 1
Views: 3347
Reputation: 4097
You have to use Facebook's SDK to share: FBSDKShareKit
You can install it using cocoa pods:
pod 'FBSDKShareKit'
Example
#import <FBSDKShareKit/FBSDKShareKit.h>
-(IBAction)sharingOnFacebook:(id)sender {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"https://myPageWeb/"];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];
}
And for Twitter the steps are similar: TwitterKit
pod 'TwitterKit'
Example:
-(IBAction)sharingOnTwitter:(id)sender {
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setURL:[NSURL URLWithString:@"https://https://myPageWeb/"]];
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
/*if (result == TWTRComposerResultCancelled) {
NSLog(@"Tweet composition cancelled");
} else {
NSLog(@"Sending Tweet!");
}*/
}];
}
NOTE: Read Facebook and Twitter documentation because you need to do some steps for your app previously. Register the app, get the AppID...
Upvotes: 0
Reputation: 398
Dont check if its available anymore; isAvailable(forServiceType:), just run it direct. I faced similar issue myself
Upvotes: 1
Reputation: 578
Those have been disabled with iOS 11. You should no longer see the Facebook NOR twitter sub-menus in the iOS Settings app.
I would suggest you to use the regular sharing options or the fb/twitter APIs.
Vincent
Upvotes: 2