18.3 C
New York
Tuesday, September 17, 2024

swift – Open particular display screen in App Delegate after iOS 18 Management Heart widget is tapped (did not open URL)


I’ve created an iOS 18 Management Heart Widget that launches my app. Nonetheless I’m not in a position to detect it in AppDelegate.swift. I’ve created customized scheme funRun://beginRun in Goal => Data => URL Sorts URL Types setup in Xcode

This technique in AppDelegate.swift doesn’t fireplace in any respect and I get this error in console:

Did not open URL runFun://beginRun: Error Area=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=279, _LSFunction=-[_LSDOpenClient openURL:fileHandle:options:completionHandler:]}
 func utility(_ app: UIApplication, open url: URL, choices: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print("Scheme (url.scheme)")
        print("Host (url.host)")
        return true
    }

I attempted this reply to no avail: iOS 18 Management Widget that opens a URL

Even including EnvironmentValues().openURL(url) as advised right here didn’t assist.

 @MainActor
    func carry out() async throws -> some IntentResult & OpensIntent {
        let url = URL(string: "funRun://beginRun")!
        EnvironmentValues().openURL(url)
        return .consequence(opensIntent: OpenURLIntent(url))
    }

Right here is my extension code:
My aim is to detect the url string from the request, so I can resolve which display screen to launch from AppDelegate’s open url technique. Once I check this with iOS 18 RC it doesn’t work both in simulator or on actual system

import AppIntents
import SwiftUI
import WidgetKit

@obtainable(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *)
struct StartRunControl: ControlWidget {
    var physique: some ControlWidgetConfiguration { 
                                               
        StaticControlConfiguration(
            type: "identify.funRun.StartRun",
            supplier: Supplier()
        ) { worth in
                ControlWidgetButton("Hi there",
                                    motion: MyIntent()) { hello in
                    Label("Begin", systemImage: "solar.min.fill")
                }
        }
        .displayName("Begin run")
        .description("Opens a run display screen.")
    }
}
 
@obtainable(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *)
extension StartRunControl {
    struct Supplier: ControlValueProvider {
        var previewValue: Bool {
            false
        }

        func currentValue() async throws -> Bool {
            let isRunning = true // Verify if the timer is operating
            return isRunning
        }
    }
}

@obtainable(iOS 18.0, watchOS 11.0, macOS 15.0, visionOS 2.0, *)
struct MyIntent: AppIntent {
    static let title: LocalizedStringResource = "My Intent"
    static var openAppWhenRun: Bool = true

    init() {}

    @MainActor
    func carry out() async throws -> some IntentResult & OpensIntent {
        let url = URL(string: "funRun://beginRun")!
        EnvironmentValues().openURL(url)
        return .consequence(opensIntent: OpenURLIntent(url))
    }
}

I even checked data.plist and it appears okay.

    CFBundleURLTypes
    
        
            CFBundleTypeRole
            Editor
            CFBundleURLName
            beginRun
            CFBundleURLSchemes
            
                funRun://beginRun
            
        
    

Does anybody know the place the issue could be?
Thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles