0

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

Community
  • 1
  • 1
Sailendra
  • 1,318
  • 14
  • 29
  • So what is suppose to happen if I see the share on my laptop or an Android phone? – WizKid Feb 07 '17 at 06:39
  • Hi WizKid, I think it will redirect to respective app store in laptop and in android if the app is installed, then open the app, else redirect to play store – Sailendra Feb 07 '17 at 06:50
  • Hi @SailendraKumarDhal In step 1, from where did you get linkUrl? – kinza Jan 28 '19 at 11:08

3 Answers3

0

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

Community
  • 1
  • 1
Sivajee Battina
  • 4,124
  • 2
  • 22
  • 45
  • Hi Sivajee thanks for your answer. Yes I have already tried the universal link functionality. There is bit complexity in web end to set up the apple-app-site-association file. And here is no web app. – Sailendra Feb 07 '17 at 06:54
  • yes how can I build that custom url? any suggestions – Sailendra Feb 07 '17 at 06:57
  • Yes. follow this link https://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629 – Sivajee Battina Feb 07 '17 at 07:00
  • This link also might useful to you: http://stackoverflow.com/questions/33821603/handle-screens-based-on-custom-url-scheme-using-uistoryboard – Sivajee Battina Feb 07 '17 at 07:01
0

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:

  1. Create an account here

  2. Install and link the SDK (pod 'Branch')

  3. 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)

Branch routing

  1. 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)
    
  2. 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()
        }
    
    }) 
    
ThunderStruct
  • 1,504
  • 6
  • 23
  • 32
0

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...

Sailendra
  • 1,318
  • 14
  • 29