Я использую Firebase DynamicLinks SDK, чтобы показать пользователям всплывающее окно с приглашением, которое отлично работает, когда приложение установлено для обоих случаев.
Ссылка перенаправляет пользователя в магазин, когда приложение не установлено. Но он не показывает всплывающее окно с приглашением, кажется, когда пользователь устанавливает приложение и нажимает кнопку открытия в магазине приложений, он не несет с собой информацию о ссылке.
Ниже приведен код в моем делегате сцены
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
let initialWindow = UIWindow(windowScene: windowScene)
initialWindow.makeKeyAndVisible()
AppSharedPoint.shared.setupWindow(window ?? initialWindow) {
if let url = connectionOptions.userActivities.first?.webpageURL {
AppSharedPoint.shared.handle(link: url)
} else if let url = connectionOptions.urlContexts.first?.url {
AppSharedPoint.shared.handle(link: url)
} else if let url = connectionOptions.userActivities.first?.referrerURL {
AppSharedPoint.shared.handle(link: url)
}
}
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let url = userActivity.webpageURL {
AppSharedPoint.shared.handle(link: url)
} else if let url = userActivity.referrerURL {
AppSharedPoint.shared.handle(link: url)
}
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let firstUrl = URLContexts.first?.url else {
return
}
AppSharedPoint.shared.handle(link: firstUrl)
}
Пожалуйста, предложите способ исправить или отладить это, когда приложение устанавливается из Appstore по ссылке.
Спасибо
Попробуйте написать приведенный ниже метод в appdelegate. Вы получите динамическую ссылку.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
print(dynamicLink.url)
return true
} else {
return false
}
}
Приятно это слышать!
В моем случае я реализовывал функциональность следующей функции в scenedelegate.
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let firstUrl = URLContexts.first?.url else { return } AppSharedPoint.shared.handle(link: firstUrl) }
Ноfunc application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool
также был в appdelegate, который не позволял запускать функцию Scenedelegate. удалил код appdelegate и все заработало