Handy dynamic links manager based of Firebase Dynamic Links.
File
-> Swift Packages
-> Add Package Dependency...
https://github.com/AppCraftTeam/appcraft-ACDynamicLinks-iOS.git
enum PathType: String {
case mainScreen
case settingsScreen
case unknown
}
let generationData = GenerationData(urlStringPrefix: "https://www.mywebsite.com/", // fallback URL
domainURLPrefix: "https://myapp.page.link", // from firebase console
iOSBundle: Bundle.main.bundleIdentifier ?? "com.myiosapp.isnice",
appStoreID: "1337133713", // might not work without it
androidBundle: "com.myandroidapp.isnice") // to provide cross-platform compatibility
dynamicLink = ACDynamicLink(generationData: generationData)
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let canOpenURL = dynamicLink.readFromURL(url) { path in
// handle nav path
}
return canOpenURL
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let canOpenURL = dynamicLink.readFromUserActivity(userActivity) { path in
// handle nav path
}
return canOpenURL
}
Example of handling nav path:
func handleNavPath(_ navPath: NavigatablePath?) {
guard let navPath = navPath else { return }
let appNavPath = AppNavPath(navigatablePath: navPath)
guard appNavPath.type != .unknown else { return }
switch appNavPath.type {
case .mainScreen:
// push/present whatever you need
break
case .settingsScreen:
// push/present whatever you need
break
case .unknown:
// push/present whatever you need
break
}
}
struct AppNavPath {
let type: PathType
let id: String?
init(navigatablePath: NavigatablePath) {
self.type = PathType(rawValue: navigatablePath.pathSuffix) ?? .unknown
self.id = navigatablePath.id
}
}
dynamicLink.generate(pathSuffix: String, id: String?, completion: @escaping (URL?) -> Void)
Example of creating a link
func generateLink(path: AppNavPath) {
dynamicLink.generate(pathSuffix: path.type.rawValue, id: path.id) { [weak self] url in
// example of sharing a link
guard let url = url else { return }
let vc = UIActivityViewController(activityItems: [url.absoluteString], applicationActivities: nil)
vc.popoverPresentationController?.sourceView = self?.view
vc.modalPresentationStyle = .fullScreen
self?.present(vc, animated: true)
}
}
There is an [Example project](https://raw.github.com/AppCraftTeam/appcraft-dynamic-links-ios/main//Example project) to help you figure it all out.
Do not forget to set up Firebase Console and add GoogleService-Info.plist to your project
If your project already has Firebase framework installed, you will face crashes as ACDynamicLink already contains that dependency. Remove the original dependency to avoid crashes.
Distributed under the MIT License.
Email: [email protected]
link |
Stars: 0 |
Last commit: 5 days ago |
Set Example Project's ACDynamicLink dependency to .upToNextMajor
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics