0.6 C
New York
Tuesday, January 14, 2025

swift – Unable to Open Important App from Motion Extension in iOS 18 – Beforehand Working Strategies Now Fail


I am creating an iOS app with an Motion Extension, and I am dealing with a vital concern in iOS 18. The performance to open the principle app from the extension, which was working in iOS 17 and earlier, is not functioning in iOS 18.

Earlier Implementations (Each labored as much as iOS 17, each fail in iOS 18):

Unique Technique in motion view controller

    personal func restore() {
        let publicURL = String(kUTTypeURL)
        let publicText = String(kUTTypeText)

        let extensionItem: NSExtensionItem = extensionContext?.inputItems.first as! NSExtensionItem
        let itemProvider = extensionItem.attachments?.first as! NSItemProvider
        if itemProvider.hasItemConformingToTypeIdentifier(publicURL) {
            itemProvider.loadItem(forTypeIdentifier: publicURL, choices: nil, completionHandler: { [weak self] merchandise, _ in
                if let fileURL: NSURL = merchandise as? NSURL,
                   let tmpURL = VPRealmManager.restore(url: fileURL as URL)
                {
                    let sharedDefaults = UserDefaults(suiteName: Key.AppGroup.Identifier)!
                    sharedDefaults.set(tmpURL.absoluteString, forKey: "backup_file_key") // そのページのURL保存
                    sharedDefaults.synchronize()
                    self?.openVoicepaperApp(path: "restore")
                }
            })
        }

        closeExtension()
    }

func openVoicepaperApp(path: String = "") {
    let url = NSURL(string: "voicepaper2://" + path)
    let selectorOpenURL = sel_registerName("openURL:")
    let context = NSExtensionContext()
    context.open(url! as URL, completionHandler: nil)

    var responder = self as UIResponder?
    whereas responder != nil {
        if responder?.responds(to: selectorOpenURL) == true {
            responder?.carry out(selectorOpenURL, with: url)
        }
        responder = responder!.subsequent
    }
}

Simplified Technique:

func openVoicepaperApp(path: String = "") {
    if let url = URL(string: "voicepaper2://" + path) {
        extensionContext?.open(url, completionHandler: nil)
    }
}

Within the Important App (AppDelegate.swift):

func utility(_ app: UIApplication, open url: URL, choices: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    // ... different URL dealing with logic ...

    let DefaultsForAppGroup = UserDefaults(suiteName: Key.AppGroup.Identifier)!
    if url.absoluteString.incorporates("restore"), let fileUrl = DefaultsForAppGroup.object(forKey: "backup_file_key") as? String,
       let backupFileURL = URL(string: fileUrl)
    {
        // Present alert and carry out restore
    }

    return true
}

The Drawback:

Each implementations of openVoicepaperApp within the Motion Extension fail to open the principle app in iOS 18, whereas they each labored in iOS 17 and earlier variations. This prevents the restore course of from beginning in iOS 18.

Any insights, ideas, or different approaches can be significantly appreciated. Thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles