Ios Appdelegate打印()不工作
我想从和URL打开我的iOS应用程序,但当我将NSURL放入基金应用程序时,print()无法工作 请参阅这里Ios Appdelegate打印()不工作,ios,iphone,swift,Ios,Iphone,Swift,我想从和URL打开我的iOS应用程序,但当我将NSURL放入基金应用程序时,print()无法工作 请参阅这里 import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var openUrl:NSURL? //This is used when to save state when App is not running
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var openUrl:NSURL? //This is used when to save state when App is not running before the url trigered
func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//print("Host: \(url.host!)")
//let url = url.standardized
//NotificationCenter.default.post(name: NSNotification.Name(rawValue: "HANDLEOPENURL"), object:url!)
print("bbb")
return true
}
}
没有具有该签名的AppDelegate方法,因此不会调用它
func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
正确的方法签名是:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool`
你把它和这个方法混淆了
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
编辑
要响应从web到iOS的链接,请使用
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
为什么要使用
Foundation
而不是swift?什么叫“应用程序打印()不工作”?你希望看到什么?你到底看到了什么?除了@AshleyMills的评论:你收到任何警告/问题了吗?我无法重现此错误emulator的调试屏幕上没有显示任何内容,但当我删除行openURL url:NSURL时,我可以在屏幕中看到bbb??为什么?我希望看到bbb,但我不能,当删除openURL url:NSURL时,bbb会出现在屏幕上,它甚至没有使用这个==func应用程序(application:UIApplication){print(“bbb”)}@tumaz打印,我想你需要回顾一下iOS应用程序开发和Swift的基础知识。不能期望调用AppDelegate中的任意方法。它们需要符合苹果在其框架中所记录的内容。我只是想在androidfunc应用程序IDbecomeactive(u应用程序:UIApplication){print(“bbb”)}上尝试一下。这是电话,请查看文档