当使用openUrl从TodayExtension打开时,如何调试iOS App?

问题描述 投票:0回答:1

我有一个带有Today Extension的微型应用程序,我创建了一个自定义URL方案。然后,在扩展中单击UIButton之后,我调用了open函数,例如

extensionContext?.open(URL(string: "todayextensionexample://inform")!, completionHandler: nil)

该应用程序已成功启动,但是我无法对其进行调试。

我尝试3种不同的方法。

首先是要在应用程序方案中启动可执行文件的开放式调试Edit Scheme -> Info -> Wait for executable to be launched,但是应用程序等待并且没有启动,因此没有调试。

我的(打开URL:URL)功能如下:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

    NotificationCenter.default.post(name: NSNotification.Name.urlOpenedNotification, object: nil, userInfo: nil)

    return true

}

在ViewController的viewDidLoad方法中;

override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(notificationHandler(_:)), name: NSNotification.Name.urlOpenedNotification, object: nil)

    }

这是我的第二种方法。

3。方法是使用解析URL参数并将其记录为如下所示:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {


let sendingAppID = options[.sourceApplication];
print("source application = \(sendingAppID ?? "Unknown") ")

guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
    let path = components.path,
    let params = components.queryItems else {
        print("Invalid URL or album path missing")
        return false
}



print("components > ", components)
print("path > ", path)
print("params >", params)

var param: [String: Any] = ["components": components, "path": path, "params": params];

NotificationCenter.default.post(name: NSNotification.Name.urlOpenedNotification,
                                object: nil,
                                userInfo: param)


return true
}

在3.方法中,我尝试使用Notification&打印一些变量。

在我提出问题之前;我将某些print()更改为NSLog(),但在Device -> Show Logs中没有任何作用。

[应用程序已用openUrl打开,但是我无法调试它,因为如果我启动TodayExtension目标,则应用程序未调试,反之,如果启动了应用程序目标,当我单击TodayExtension按钮,然后在其后台运行时再次打开该应用程序] >

func application(_ app: UIApplication, open url: URL ...)

功能不起作用。我已经看到了真实设备的调试,但没什么可看的。

单击“今日扩展”上的按钮之后Xcode已经启动了主要应用程序目标,并且我将能够查看所有日志吗?

如何调试它,并查看其是否成功运行?

我有一个带有Today Extension的微型应用程序,我创建了一个自定义URL方案。然后,在扩展中单击UIButton之后,我调用了诸如extensionContext?.open(URL(string:“ ...

ios swift nsnotificationcenter
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.