无法打开具有不同尾部小部件 SwiftUI 的深层链接

问题描述

我在fidget中设置了四个按钮,每个按钮打开Deeplink的尾部不同,然后我在SceneDelegate里面处理Deeplink,但是每次在SceneDelegate里面处理Deeplink时,每个Deeplink都一样,为什么?

我的代码

struct WidgetTestEntryView : View {
    var entry: Provider.Entry
    
    var deeplinkURLFirst: URL {
        URL(string: "widget-DeepLinkWidget://widgetFamily/0")!
    }
    var deeplinkURLSecond: URL {
        URL(string: "widget-DeepLinkWidget://widgetFamily/1")!
    }
    
    var deeplinkURLThird: URL {
        URL(string: "widget-DeepLinkWidget://widgetFamily/2")!
    }
    
    var deeplinkURLFourty: URL {
        URL(string: "widget-DeepLinkWidget://widgetFamily/3")!
    }
    
    var widgetLabel = "Favourites"

    var body: some View {
        
       
        
        vstack {
            HStack(spacing: 100){
                Text(widgetLabel).foregroundColor(.white).font(.system(size: 16,weight: .bold,design: .default)).offset(y: 2)
                Image("Label").resizable().frame(width: 80,height: 15,alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                
            }.frame(maxWidth: .infinity,maxHeight: 50,alignment: .center).background(Color.black).offset(y: -9)
            
            HStack {
                Spacer()
                Button(action: {}) {
                    
                    Image(imageFromAppGroup(key: "image0")).resizable().frame(width: 70,height: 70)
                        .cornerRadius(10)
                        .background(Color(red: 0.218,green: 0.215,blue: 0.25))
                    
                }.widgetURL(deeplinkURLFirst).cornerRadius(10)

                Button(action: {}) {
                    Image(imageFromAppGroup(key: "image1")).resizable().frame(width: 70,blue: 0.25))
                }.widgetURL(deeplinkURLSecond).cornerRadius(10)

                Button(action: {}) {
                    Image(imageFromAppGroup(key: "image2")).resizable().frame(width: 70,blue: 0.25))
                }.widgetURL(deeplinkURLThird).cornerRadius(10)

                Button(action: {}) {
                    Image(imageFromAppGroup(key: "image3")).resizable().frame(width: 70,blue: 0.25))
                }.widgetURL(deeplinkURLFourty).cornerRadius(10)

                Spacer().frame(width: 10,height: 10,alignment: .center)
                
            }.background(Color(red: 0.118,green: 0.118,blue: 0.15)).offset(y: -9)
            
            
        }.frame(maxWidth: .infinity,maxHeight: .infinity,alignment: .center).background(Color(red: 0.118,blue: 0.15)).onAppear {
            print("I AM HERE !!!")
            
        }
    }
}

控制台日志:

widget-DeepLinkWidget://widgetFamily/3
widget-DeepLinkWidget://widgetFamily/3
widget-DeepLinkWidget://widgetFamily/3
widget-DeepLinkWidget://widgetFamily/3

必须是:

widget-DeepLinkWidget://widgetFamily/0
widget-DeepLinkWidget://widgetFamily/1
widget-DeepLinkWidget://widgetFamily/2
widget-DeepLinkWidget://widgetFamily/3

索引的结尾取决于特定的按钮。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)