iOS FBSDKShareLinkContent Share Post - imageURL not loading on Mobile Data - ios

I am sharing a Facebook post using FBSDKShareKit framework using FBSDKShareLinkContent. I am setting the content's imageURL to load an image for the post to be shared. The problem is, when I am sharing the post while on a mobile internet/3G connection, the link's image is not loading and shared on the post. Meanwhile, it is working fine when sharing the link while on a Wifi connection. To further illustrate, please refer to the screenshot below:
Screenshot: http://i.imgur.com/S2Z4Ddi.png?1
My apologies as I can't post images yet due to my reputation.
I am using the following code to make and share the content.
let content:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: linkURL)
content.contentTitle = nsTitle as! String
content.contentDescription = nsDesc as! String
content.imageURL = NSURL(string: imageURL)
let button:FBSDKShareButton = FBSDKShareButton()
button.frame = CGRectMake(0, 0, 0, 0)
button.shareContent = content
button.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
Any ideas?
Thanks in advance.

Tested with other devices, could just potentially be a factory defect on the iPhone6's 3G.
The testing is done by using 2 different SIM Cards on the same phone, same result. Meanwhile both SIM Cards are also tested on another device, different result. Speedtest is also done to check. both of which are comparable in speed.

Related

How to implement iOS app link Facebook functionality in swift 3?

I have tried many ways to achieve this but failed.
I have to share info on facebook with a URL and when clicked on the url, it will redirect to my app's specific page.
step# 1
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: linkUrl) as URL!
content.contentTitle = "Test"
content.quote = "game"
content.contentDescription = "This is a test game to test Fb share functionality"
content.imageURL = NSURL(string: imgUrl) as URL!
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.native
dialog.fromViewController = vc
dialog.shareContent = content
// if you don't set this before canShow call, canShow would always return YES
if !dialog.canShow() {
// fallback presentation when there is no FB app
dialog.mode = FBSDKShareDialogMode.feedBrowser
}
dialog.show()
It is working and successfully sharing the post. When I clicked on the link, it is redirecting to the app, not much info to redirect to a particular ViewController.
Step# 2
let properties = [
"fb:app_id": "Fb_id",
"og:type": "article",
"og:title": "Test",
"og:description": "This is a test game to test Fb share functionality",
"og:image" : urlImg,
"og:url" : linkUrl,
]
let object : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject.init(properties: properties)
// Create an action
let action : FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
action.actionType = "news.publishes"
action.setObject(object, forKey: "article")
// Create the content
let content : FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "article"
FBSDKShareDialog.show(from: vc, with: content, delegate: nil)
Here I am using Open Graph to post and successfully posted the Info. But con't redirecting to my app when clicked the link.
NB:
I don't have web Application.
My goal is to share a post with a app link. When clicked on that link it will open the app and redirect to a specific page if app is installed, otherwise redirect to the AppStore. So what should be the link format or how can I build the link to achieve this functionality?
Please help.
Thanks in advance
Use Universal Links. If you want to achieve something like this using universal link is a good idea. You can redirect to a specific page in your app if the app is installed otherwise it will navigate to appstore.
Here is how to implement universal links if you are not aware of:
Set up universal links - Raywenderlich
Universal links - Appsflyer
Note: Please ignore this, if this is not what you are looking for
I managed to achieve the same result using Branch.io. It's a very powerful app routing SDK and their console practically guides you down the routing scheme in a very visual and understandable manner.
The way it works is by dynamically creating a webpage with certain redirecting features according to what you set in the dashboard. You can then use that generated webpage to share it on Facebook or anywhere else.
Here's how you can integrate it:
Create an account here
Install and link the SDK (pod 'Branch')
Set up the routing mechanism using Branch's dashboard (it's guided and pretty straightforward, you just fill in the branches below). You can always change how the diagram looks like (if you want to always end up on a website or so, for instance)
Initialize the share data in your app
let branchUniversalObject: BranchUniversalObject = BranchUniversalObject(canonicalIdentifier: "any ID here") // just for tracking count and analytics
branchUniversalObject.title = "some title" // This will appear as the shared content's title
branchUniversalObject.contentDescription = "some description" // This will appear as the shared content's description
branchUniversalObject.imageUrl = "www.example.com/test.png"
branchUniversalObject.addMetadataKey("uid", value: self.userId)
branchUniversalObject.addMetadataKey("otherInfo", value: self.otherInfo)
Generate link and share the link on Facebook
let linkProperties = BranchLinkProperties()
linkProperties.channel = "Facebook"
linkProperties.feature = "Share"
// generate link
branchUniversalObject.getShortUrl(with: linkProperties, andCallback: { (shareURL, error) in
if error != nil {
// handle error
}
// init Facebook share data
let content = FBSDKShareLinkContent()
content.contentTitle = "Some title"
content.contentURL = URL(string: shareURL) // this URL handles the redirecting according to your dashboard's settings
content.contentDescription = "Some description"
content.imageURL = URL(string: "www.example.com/test.png")
// create Facebook share dialog
let dialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = content
dialog.mode = .automatic
if dialog.canShow() {
dialog.show()
}
})
Yes, I achieved this functionality by setting up the metadata in the server end.
References: https://developers.facebook.com/docs/applinks
https://developers.facebook.com/docs/applinks/ios
Thanks...

Using Branch.io generated link with Facebook share dialog

I went through Branch.io's documentation a lot over the past few days and I can't seem to pinpoint the problem. I got the generated link to work properly by setting up the BranchUniversalObject as follows:
let branchUniversalObject: BranchUniversalObject = BranchUniversalObject(canonicalIdentifier: "ios_share_user")
branchUniversalObject.title = "My Title"
branchUniversalObject.contentDescription = "My Description"
branchUniversalObject.imageUrl = "www.example.com/image.jpg"
branchUniversalObject.addMetadataKey("id", value: self.userId)
branchUniversalObject.addMetadataKey("type", value: self.userType)
let linkProperties = BranchLinkProperties()
linkProperties.channel = "Facebook"
linkProperties.feature = "Share"
branchUniversalObject.getShortUrl(with: linkProperties, andCallback: { (shareURL, error) in
if error != nil {
print(error!)
return
}
// using shareURL here
})
The generated URL works perfectly fine, but only when launched from Notes or Messages apps. Safari always redirects me to the AppStore and so does the Facebook app when I try sharing the URL like this:
let content = FBSDKShareLinkContent()
content.contentTitle = "My Title"
content.contentURL = shareURL // generated above
content.contentDescription = "My Description"
content.imageURL = "www.example.com/image.jpg"
let dialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = content
if dialog.canShow() {
dialog.show()
}
That shows up the dialog and shares the content as intended, but the link always redirects me to the AppStore just like in Safari.
Here's a screenshot of the Dashboard:
I also have applinks:myLinkDomain.app.link and applinks:myLinkDomain-alternate.app.link in the Associated Domains, branch_app_domain = myLinkDomain.app.link along with branch_key = ["live": "key_live_myKey"] in Info.plist, and AppDelegate is properly set.
What am I missing to get the app to open from Safari and Facebook instead of getting redirected to the AppStore?
I'm deploying the app for iOS 9.3+
Thanks!
I came across this link and it shows that the problem isn't with Branch.io SDK's setup by any means, but a limitation imposed by Apple. The only workaround is using Branch's Deepviews, which unfortunately I can't use in my case.
Hope Branch.io figure out a way around that! ...And possibly update their documentation to clearly state that some app browsers are not supported

Facebook Share Button in navigation bar appears inactive

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);

How to share Facebook page using Xamarin.iOS Facebook SDK?

I use this code in my apps to share Facebook pages:
class func shareWithDialog(viewController : UIViewController, delegate : FBSDKSharingDelegate, contentTitle: String, contentUrl: NSURL = url, contentDescription: String) {
let content = FBSDKShareLinkContent()
content.contentTitle = contentTitle
content.contentURL = contentUrl
content.contentDescription = contentDescription
let dialog = FBSDKShareDialog()
dialog.fromViewController = viewController
dialog.shareContent = content
dialog.mode = FBSDKShareDialogMode.FeedBrowser
dialog.delegate = delegate
dialog.show()
}
In the native code (above) FBSDKShareLinkContent.contentURL is set to the facebook page I want to share. I'm using Xamarin.Facebook.iOS.4.5.1.0 nuget package to add this functionality into a Xamarin app. The thing is that this SDK is similar to the native SDK but class ShareLinkContent doesn't have the property contentURL (it does have a ImageURL property).
I might be using the wrong class, but I could'n find the right class (other classes in the SDK are intended for sharing images and videos).
Thanks to Jason Steele I looked closer and see that contentUrl property was replaced by setContentURL() method. I used this method to point to the Facebook page I wanted to share and it worked.
It was a silly question after all ;)

Facebook share success callback?

I would like to know if I can check if my content was actually shared in Facebook?
I'm using Facebook SDK 4.1.x and FBSDKShareButton
The user has to authorize my app in Facebook, so I have a FB access token.
And I have this method to test the Share button
func newShareButton(){
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com.br")
content.contentTitle = "Test title"
content.contentDescription = "Test description"
content.imageURL = NSURL(string: "https://www.google.com.br/images/nav_logo225.png")
shareButton.shareContent = content
}
Everything is working fine, but I can't figure it out how to get the response, if the user actually shared the content.
Is it possible? Do I have to use other method to get the result?
Thanks in advance!

Resources