ios - UniversalLink 在 iOS 14 设备中不起作用
问题描述
这是我添加的功能我有一个支持 UniversalLink 的应用程序。但它无法在 iOS 14 上运行。它没有打开应用程序,而是路由到网络。遵循与其他文章中给出的相同步骤,但仍然面临相同的问题。请发送您对此的建议。
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation]
)
}
func scene(_ scene: UIScene, continue userActivity: NSUserActivity)
{
print("Continue User Activity called: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb
{
if let url = userActivity.webpageURL
{
"\(url.absoluteString)".printOn()
if url.absoluteString == WebserviceCall_Swift.universal_url + "deposit-balance" //navigate to payment screen
{
Singleton.shared.strNavScreensUniversal = "deposit"
let scene = UIApplication.shared.connectedScenes.first
if let mySceneDelegate : SceneDelegate = (scene?.delegate as? SceneDelegate)
{
let rootViewController = mySceneDelegate.window!.rootViewController as! UINavigationController
if !Singleton.isKeyPresentInUserDefaults(key: Singleton.USERINFO)
{
let vc : LoginVC = BaseApp.sharedInstance.getViewController(storyboardName:StoryboardType.main.rawValue, viewControllerName: LoginVC.nameOfClass)
rootViewController.pushViewController(vc, animated: true)
}
else
{
self.setLoginData()
let vc : CustomTabbarController = BaseApp.sharedInstance.getViewController(storyboardName: StoryboardType.main.rawValue, viewControllerName: CustomTabbarController.nameOfClass)
//AppDelegate.shared().mainNavBar.pushViewController(homeVC, animated: true)
rootViewController.pushViewController(vc, animated: true)
}
}
}
else if url.absoluteString == WebserviceCall_Swift.universal_url + "contest" //navigate to payment screen
{
Singleton.shared.strNavScreensUniversal = "contest"
let scene = UIApplication.shared.connectedScenes.first
if let mySceneDelegate : SceneDelegate = (scene?.delegate as? SceneDelegate)
{
let rootViewController = mySceneDelegate.window!.rootViewController as! UINavigationController
if !Singleton.isKeyPresentInUserDefaults(key: Singleton.USERINFO)
{
let vc : CustomTabbarController = BaseApp.sharedInstance.getViewController(storyboardName: StoryboardType.main.rawValue, viewControllerName: CustomTabbarController.nameOfClass)
rootViewController.pushViewController(vc, animated: true)
}
else
{
self.setLoginData()
let vc : CustomTabbarController = BaseApp.sharedInstance.getViewController(storyboardName: StoryboardType.main.rawValue, viewControllerName: CustomTabbarController.nameOfClass)
//AppDelegate.shared().mainNavBar.pushViewController(homeVC, animated: true)
rootViewController.pushViewController(vc, animated: true)
}
}
}
else
{
let arrParams = url.absoluteString.components(separatedBy: "/")
if Singleton.isKeyPresentInUserDefaults(key: Singleton.USERINFO)
{
self.setLoginData()
}
Singleton.shared.strNavScreensUniversal = "indv"
Singleton.shared.contestID = "\(arrParams.last ?? "")"
let scene = UIApplication.shared.connectedScenes.first
if let mySceneDelegate : SceneDelegate = (scene?.delegate as? SceneDelegate)
{
let rootViewController = mySceneDelegate.window!.rootViewController as! UINavigationController
let vc : CustomTabbarController = BaseApp.sharedInstance.getViewController(storyboardName: StoryboardType.main.rawValue, viewControllerName: CustomTabbarController.nameOfClass)
//AppDelegate.shared().mainNavBar.pushViewController(homeVC, animated: true)
rootViewController.pushViewController(vc, animated: true)
}
"contest id == \(arrParams.last ?? "nil")".printOn()
}
var parameters: [String: String] = [:]
URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.forEach
{
parameters[$0.name] = $0.value
}
}
//handle url and open whatever page you want to open.
}
}
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).
if let userActivity = connectionOptions.userActivities.first
{
if Singleton.shared.strNavScreensUniversal != ""
{
return
}
self.scene(scene, continue: userActivity)
}
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene)
{
AppsFlyerLib.shared().start()
// ...
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
func setLoginData()
{
let dicTemp = Singleton.getUserInfoFromUserdefault(withKey: Singleton.USERINFO)
let dicDetails = dicTemp.value(forKey: "data") as! NSDictionary
"user id -------\(dicTemp)".printOn()
Singleton.shared.USERID = "\(dicDetails.value(forKey: "_id") ?? "")"
Singleton.shared.USERTOKEN = "\(dicDetails.value(forKey: "token") ?? "")"
Singleton.shared.isLoggedIn = true
}
//MARK:Get contest details
func contests_single(contest_id:String)
{
let dict = [
"contest_id":contest_id,
"user_id":Singleton.shared.USERID,
]
Loader.sharedInstance.showLoader(msg: Constants.PLEASE_WAIT )// Start
let service = WebserviceCall_Swift()
DispatchQueue.global(qos: .background).async{
service.callServiceWith(parameterDict: dict ,isAuth:true, url: "\(Constants.contests_single)" ,type:"POST", onCompletion: { (sender) in
DispatchQueue.main.async
{
Loader.sharedInstance.stopLoader()
"Loader Close----------------------------".printOn()
if sender.isKind(of: NSString.self)
{
let error = sender as! String
if error == Constants.No_Internet
{
Singleton.actionShowNetwotkError(compblock: { (txt) in
if txt == "Retry"
{
self.contests_single(contest_id: contest_id)
}
})
}
else
{
Singleton.actionShowMessage(message: Constants.SomethingWentWrong)
}
}
else
{
let arrResult = sender as! NSArray
let json = arrResult.object(at: 0) as! NSDictionary
if Int("\(json.object(forKey: "status") ?? "0")") == 200
{
"Data is \(json)".printOn()
"get single contest Api response \(json.value(forKey: "data") ?? "")".printOn()
}
else if Int("\(json.object(forKey: "status") ?? "0")") == 201
{
Singleton.actionShowMessage(message: "\(json.object(forKey: "message") ?? "0")")
}else if Int("\(json.object(forKey: "status") ?? "0")") == 401
{
AlertViewS.ShowAlertTitle(AlertTitle: "", Message: "\(json.object(forKey: "message") ?? "")", ThemeColor: [ AppDelegate.shared().APP_COLOR], BtnAlignmentType: .Horizontal, ButtonOfArrayInString: ["OK"])
{ (result) in
if result == "OK"
{
AppDelegate.shared().logout()
}
}
}
else
{
Singleton.actionShowMessage(message: Constants.SomethingWentWrong)
}
}
}
})
}
}
}
解决方案
推荐阅读
- powershell - 如何使用 powershell 将参数传递给 ADF 管道
- java - ImageView 不正确的 XY 坐标
- ruby-on-rails - 如何将haml与react js集成。我想使用Haml文件渲染react组件?
- spring-boot - Spring Boot Apache Camel 应用程序在容器中时不服务请求
- java - 如何在java上使用多个用户帐户的用户登录属性
- facebook-javascript-sdk - 我收到此错误“找不到变量:FBSDKApplicationDelegate”
- java - 我的 Hibernate CRUD 没有在表中保存数据,但它显示表为空
- python-3.x - 如何计算指定索引以外的元素的总和?
- php - 随机化对象数组的一部分
- php - 将用户从年龄验证重定向到原始网址