How to create a Dynamic link in Firebase programmatically? Swift
Thanks for including the output in the comments, that made it easy to spot the errors.
- Only include the domain in the dynamic link domain, e.g.
let dynamicLinkDomain = "a5481.app.goo.gl"
- To test further: you can debug the long link by adding "&d=1" to the end of the long lin, and pasting it in to a browser.
How to create a Firebase Dynamic Link programmatically (iOS)?
Does this page helps you https://firebase.google.com/docs/dynamic-links/ios/create ?
You can find example code at https://github.com/firebase/quickstart-ios/tree/master/dynamiclinks
Dynamic link web URL query item is empty in Swift iOS
As mentioned in the comments you cannot create a dynamic link with variable product id in the firebase console, instead you need to generate it on the go. You can also include additional parameters if needed which may help in analytics for example if you would like to know which user share the link and what its impact...
In my opinion it's better to add product id as query parameter in the link. Moreover it will also be helpful in case of multi parameters. You can parse it easily with the parameter name for example:
var productId: String?
let urlComponents = URLComponents(string: urlString)
if let queryItems = urlComponents?.queryItems {
for queryItem in queryItems {
if queryItem.name == "product_id" {
productId = queryItem.value
}
}
}
Here is my code for generating dynamic link programmatically.
func generateAndShareDynamicLink(event: Event, controller: UIViewController, presentationCompletion: @escaping (() -> Void), dismissCompletion: @escaping (() -> Void) ) {
let user = Utility.shared.getCurrentUser()!
let ownReferralCode = user.ownReferralCode.value
let offerShareUrlString = youAPILink + "?referral=" + ownReferralCode + "&event_id=" + event.id.value + "&shared_by=" + user.userId.value + "&shared_by_name=" + user.fullName.value
let url = URL(string: offerShareUrlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!)!
let iOSNavigationParams = DynamicLinkNavigationInfoParameters()
iOSNavigationParams.isForcedRedirectEnabled = false
let linkComponents = DynamicLinkComponents(link: url, domainURIPrefix: dynamicLinkGenaricDomain)!
linkComponents.navigationInfoParameters = iOSNavigationParams
linkComponents.iOSParameters = DynamicLinkIOSParameters(bundleID: bundleId)
linkComponents.iOSParameters?.appStoreID = kAppStoreId
linkComponents.iOSParameters?.customScheme = theBarCodeInviteScheme
linkComponents.androidParameters = DynamicLinkAndroidParameters(packageName: androidPackageName)
let descText = "\(user.fullName.value) has shared an event with you, check it out!"
linkComponents.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkComponents.socialMetaTagParameters?.title = "App Name"
linkComponents.socialMetaTagParameters?.descriptionText = descText
linkComponents.socialMetaTagParameters?.imageURL = tbcLogoUrl
linkComponents.otherPlatformParameters = DynamicLinkOtherPlatformParameters()
linkComponents.otherPlatformParameters?.fallbackUrl = URL(string: barCodeDomainURLString)
linkComponents.shorten { (shortUrl, warnings, error) in
guard error == nil else {
presentationCompletion()
controller.showAlertController(title: "Share Event", msg: error!.localizedDescription)
return
}
if let warnings = warnings {
debugPrint("Dynamic link generation warnings: \(String(describing: warnings))")
}
let activityViewController = UIActivityViewController(activityItems: [descText, shortUrl!], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = controller.view
activityViewController.completionWithItemsHandler = { (activityType, completed:Bool, returnedItems:[Any]?, error: Error?) in
dismissCompletion()
}
controller.present(activityViewController, animated: true, completion: {
presentationCompletion()
})
}
}
How to add OFL link in Firebase dynamic linking iOS Swift?
guard let link = URL(string: "url") else { return }
let dynamicLinksDomainURIPrefix = "prefixlik"
guard let shareLink = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix) else {
print("Could not create firebace dynamiclink on console")
return
}
if let myBundleId = Bundle.main.bundleIdentifier {
shareLink.iOSParameters = DynamicLinkIOSParameters(bundleID: myBundleId)
}
shareLink.iOSParameters?.appStoreID = "XXXXXXXXX"
shareLink.androidParameters = DynamicLinkAndroidParameters(packageName: "XXXXXXXX")
guard let longDynamicLink = shareLink.url else { return }
print("The long URL is: \(longDynamicLink)")
DynamicLinkComponents.shortenURL(URL(string: "\(longDynamicLink)&ofl=https://google.com/")!, options: nil) { (url, warnings, error) in
if let error = error {
print("Oh no! Got an error ",error.localizedDescription)
return
}
if let warnings = warnings {
for warning in warnings {
print("FDL warning: \(warning)")
}
}
guard let shortUrl = url else {return}
print(shortUrl) }
Firebase.google.com Firebase Dynamic Links in iOS ( Swift )
It's hard to know exactly where your error is, but a few things to help you debug:
If you go to https://q3tyj.app.goo.gl/apple-app-site-association, you should see some JSON that points to your app. If you don't see this, make sure you've entered your team ID and your App Store ID in the project settings in the Firebase console
Make sure you're using your Bundle ID, not the shortlink domain, as your custom URL scheme in Xcode
Make sure you've enabled Associated Domains in the Capabilities tab of your Xcode project, and your domain looks like
applinks:q3tyj.app.goo.gl
Universal Links (and, therefore, Dynamic Links) generally don't work if you type them directly into the Safari address bar. Instead, try typing the URL into an app like Notes and then clicking on them from there.
Good luck!
Related Topics
Composing Video and Audio - Video's Audio Is Gone
Secure Text .Echosbullets Not Working for Password Field
Switch Statement for Imported Ns_Options (Rawoptionsettype) in Swift
Use of or Operator on Cloudkit Predicate
Swift Conditional Conformance with Any
How to Resume a Published Timer in Swiftui After Navigating to a Different Page
Can the Byte Order of Double Be Safely Reversed
Cannot Read Property 'Keycode' 'Character' Assertion Failure When Detect Modifier Key + Numeric Key
Contextual Member Has No Associated Value in Swift 3
Swift 3 - How to Insert Tableviewcells from Another View
Behavior of the Cameranode Is Unclear When Moving a 3D Model in a Scene with Scenekit
Alamofire 4 Error Request 'Extra Argument in Call'
Convert from Utc to Local Timezone Give Wrong Result
Swift 2.2 Decrementing Specific for Loop in Swift 3
How to Deal with Commas When Writing Objects to CSV in Swift
Randomize Two Arrays the Same Way Swift
Swift Implement Literalconvertible Protocol
Comparing Objects in an Array Extension Causing Error in Swift