Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Native Share Dialog in swift

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

like image 864
Ilir V. Gruda Avatar asked Jun 23 '15 12:06

Ilir V. Gruda


1 Answers

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)
like image 67
Ilir V. Gruda Avatar answered Sep 20 '22 17:09

Ilir V. Gruda