ios - 如何在此扩展程序中创建一个按钮,在不使用操作按钮的情况下在主应用程序中打开特定视图?
问题描述
我正在 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
}
解决方案
您不应该尝试在扩展中添加存储属性。如果您需要一个存储属性,在这种情况下是一个按钮,您应该根据您的用例创建一个 UIView 或 UIViewController,并将其关联到另一个 UIView 或 UIViewController。
您还应该尝试共享一些代码,因为不清楚您要的是什么。
推荐阅读
- templates - 填充和打印任意容器的 C++ 函数
- c# - C# 中的 BufferManager 和 System.Buffers.ArrayPool 有什么区别
- javascript - ember保存调用不会成功块
- tensorflow - 在我的 PC 中使用我的 train 和 eval 文件在谷歌云中训练神经网络
- ms-access - 基于组合框填充多个文本字段
- git - 如何修复.git暴露的firebase漏洞
- backup - Power BI 安全数据存储
- powershell - Send-MailMessage 正文中的 powershell 换行符
- python-3.x - 在不使用 for 循环的情况下将加权平均数提高到特定索引
- c++ - 正确发送消息 UART