首页 > 解决方案 > 如何在此扩展程序中创建一个按钮,在不使用操作按钮的情况下在主应用程序中打开特定视图?

问题描述

我正在 IOS 中设置通知内容扩展,并希望添加一个在主应用程序中打开特定视图的按钮。

我可以通过操作按钮(在底部)来做到这一点,但想在扩展视图本身中添加一个按钮。

@IBAction func btn_openapp(_ sender: Any) {

    let mystring = "mydrop://" + String(campaign_id)
    self.extensionContext?.open(URL(string: mystring)!, completionHandler: nil)

}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
{

    d_me["single"] = url.host

    print(url.host,url.scheme)
    if url.scheme == "mydrop://"
    {
        let rootViewController = self.window!.rootViewController as! UINavigationController
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let targerView = mainStoryboard.instantiateViewController(withIdentifier: "CampaignDetailViewController")
        rootViewController.pushViewController(targerView, animated: false)

    }
    return true
}

标签: iosswiftnotifications

解决方案


您不应该尝试在扩展中添加存储属性。如果您需要一个存储属性,在这种情况下是一个按钮,您应该根据您的用例创建一个 UIView 或 UIViewController,并将其关联到另一个 UIView 或 UIViewController。

您还应该尝试共享一些代码,因为不清楚您要的是什么。


推荐阅读