Xcode Swift 4 Facebook & Twitter sharing no longer working?

后端 未结 3 2106
萌比男神i
萌比男神i 2021-01-24 05:00

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

3条回答
  •  灰色年华
    2021-01-24 05:37

    You have to use Facebook's SDK to share: FBSDKShareKit

    You can install it using cocoa pods:

    pod 'FBSDKShareKit'
    

    Example

    #import 
    
    -(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...

    Facebook iOS Developers

    Twitter iOS Developers page

提交回复
热议问题