Facebook Native Share Dialog in swift

17,386

Actually I figure out a solution.

These lines of code would implement Facebook Native Share Dialog in Swift:

let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: self.contentURL)
content.contentTitle = self.contentTitle
content.contentDescription = self.contentDescription
content.imageURL = NSURL(string: self.contentURLImage)
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
Share:
17,386
Ilir V. Gruda
Author by

Ilir V. Gruda

Updated on June 19, 2022

Comments

  • Ilir V. Gruda
    Ilir V. Gruda about 2 years

    I am trying to create share button which will share a link on Facebook. The problem is that I do not want to have a login button before share button in my app, I just need to have a share button.

    I think one solution may be to use custom buttons for login and share buttons and merge these buttons in one. In that way if the user has not log in when he click share button he will be asked to login. However during the time that I was trying to achieve this I found that Native Share Dialog is even better solution because it dose not request to login at all.

    But I am struggling to find any references/tutorial/examples or anything where Native Share Dialog is used with swift. There are examples and stuffs on Obj-c but I have never used Obj-c and I do not know anything about it.

    I was hopping if anyone has any examples or can anyone point me in the right direction how to achieve Facebook Native Share Dialog in Swift.

    If not dose anyone has any example of using custom share buttons on Swift

  • Ilir V. Gruda
    Ilir V. Gruda about 9 years
    Actually I am using Facebook SDK 4.1 because I want to share a link. Until know I am being able to share a link on fb. But when I am trying to do so before sharing the link I need to login and these two function are being in separate buttons which is not what I want. For this reason I am trying to use Facebook Share Dialogs since they do not ask for login. Furthermore I am not familiar with Obj-C. But if u need to upload my cod I can
  • sirvon
    sirvon almost 9 years
    @IlirVGruda can you please provide a link to some documentation on this, iOS SDK's SharingActivityProvider. My google searches found nil.
  • bibscy
    bibscy over 5 years
    Iget error Use of undeclared type 'FBSDKShareLinkContent' What could be the cause? I do import FacebookShare module