打开一个应用程序从另一个到特定 VC
Opening an app from another one to a specific VC
我是 iOS 开发的新手,我没有找到任何具体的答案。
假设我有一个包含 2 个目标的应用程序,FirstApp (firstTarget) 和 SecondApp (secondTarget)。我在一些帖子中看到您可以从另一个应用程序打开一个应用程序,我确实这样做了:
if UIApplication.shared.canOpenURL(aUrl as! URL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(aUrl!)
} else {
// Fallback on earlier versions
}
但我可以在 SecondApp 中将其打开到特定的 VC 吗?
我在我的项目中包含了 UniversalLink 以及带有警报的 AppDelegate 方法:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("UNIVERSAL LINK")
let alert = UIAlertController(title: "Test", message:"Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
return true
}
事实是,只有在我再重复该操作 1 次后它才会起作用。这是第一次只打开应用程序。如果我返回 FirstApp 并重复该操作,则会弹出警报。
我可以用另一种方式来做吗?或者你有这种方式的解决方案吗?
通知的工作方式不一样吗?当我点击它时,它会将您重定向到特定的 VC.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let noNetworkView = UIView()
var reachability:Reachability!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let alert = UIAlertController(title: "Test", message:"Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
return true
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return true
}
func applicationWillTerminate(_ application: UIApplication) {
self.reachability.stopNotifier()
self.saveContext()
}
continueUserActivity
不会在应用程序启动时调用。您必须将 Universal Link 从 didFinishLaunchingOptions
的启动选项中拉出。请参阅此 I recommend using Branch,因为他们会为您将所有这些捆绑到一个回调中。
我是 iOS 开发的新手,我没有找到任何具体的答案。
假设我有一个包含 2 个目标的应用程序,FirstApp (firstTarget) 和 SecondApp (secondTarget)。我在一些帖子中看到您可以从另一个应用程序打开一个应用程序,我确实这样做了:
if UIApplication.shared.canOpenURL(aUrl as! URL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(aUrl!)
} else {
// Fallback on earlier versions
}
但我可以在 SecondApp 中将其打开到特定的 VC 吗?
我在我的项目中包含了 UniversalLink 以及带有警报的 AppDelegate 方法:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("UNIVERSAL LINK")
let alert = UIAlertController(title: "Test", message:"Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
return true
}
事实是,只有在我再重复该操作 1 次后它才会起作用。这是第一次只打开应用程序。如果我返回 FirstApp 并重复该操作,则会弹出警报。
我可以用另一种方式来做吗?或者你有这种方式的解决方案吗?
通知的工作方式不一样吗?当我点击它时,它会将您重定向到特定的 VC.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let noNetworkView = UIView()
var reachability:Reachability!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let alert = UIAlertController(title: "Test", message:"Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
return true
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return true
}
func applicationWillTerminate(_ application: UIApplication) {
self.reachability.stopNotifier()
self.saveContext()
}
continueUserActivity
不会在应用程序启动时调用。您必须将 Universal Link 从 didFinishLaunchingOptions
的启动选项中拉出。请参阅此