I'm trying to implement FB Share Button to Navigation Bar(with it's design).
I coded sharing with SLComposeViewController, and everything works fine.
I use only Facebook and Action icon is not what i want.
I tried to add a button as FBSDKShareButton to Navigation Bar:
but button is always inactive and looks poor:
I am sure, that I test my app on the device logged to FB. May be FBSDKShareButton needs some information about this? How?
self.fbShareButton.enabled = true
in viewDidLoad does not work.
Of course, i can make usual UIButton and assign created(or downloaded) image. But with this I lose localization and resizing.
Any thoughts?
Thanks to @Bangdel, but I think it's useful to post more detailed answer:
code is:
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.stackoverflow.com")
//content.contentTitle = "<INSERT STRING HERE>"
//content.contentDescription = "<INSERT STRING HERE>"
//content.imageURL = NSURL(string: "<INSERT STRING HERE>")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 6, 100, 32)
//You can be more accurate with CGRectMake parameters,
//but usual height of navigation bar is 44
self.navigationController!.navigationBar.addSubview(button)
In last FB SDKs only one content.something will work. If URL is added - FB will post only link. Facebook will find an image on the page, which is appropriate by FB point of view ;-)
I tested this-way button on my device and it linked me to that annoying page, which asks my login and password, when FB App is already installed on my device. In my test App I was logged in with test user, and in installed App with my usual FB Login, may be this is the issue.
Try this
public void btnClick(View v){
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
//Give any url in uriString
uriString = "http://www.opencv-tutorial-codes.blogspot.in";
sharingIntent.putExtra(Intent.EXTRA_TEXT,uriString );
sharingIntent.setPackage("com.facebook.katana");
startActivity(sharingIntent);