ImportFromDevicesCommands - The operation couldn’t be completed. (Cocoa error 66563.)

I am trying to use import from iPhone option as shown in WWDC session.

I added code

 WindowGroup {

            ContentView()

                .environment(\.managedObjectContext, persistenceController.container.viewContext)

            

        }

        .commands {

            ImportFromDevicesCommands()

        }

ContentView.swift is

 List {

                ForEach(items) { item in

                    NavigationLink {

                        Text("Item at \(item.timestamp!, formatter: itemFormatter)")

                    } label: {

                        Text(item.timestamp!, formatter: itemFormatter)

                    }

                }

                .onDelete(perform: deleteItems)

            }

            .importsItemProviders([.image,.png,.jpeg,.rawImage], onImport: { providers in

                print("checking reachability")

                return true

            })

The importsItemProviders block itself is not executed and not printing anything.

In addition I am getting alert The operation couldn’t be completed. (Cocoa error 66563.)

Is there anything to add for making this functionality work ?

  • Are there any updates to this? In addition to getting the error above, I am unable to consistently get the options to be available as they are grayed out. I feel like there is a nuance to how these are supposed to work that is not explained or documented. Could really use some thoughts here from the SwiftUI team.

Add a Comment

Replies

... anything learned since this was posted you can / wouldn't mind sharing?

I'm seeing this error when I try to add a sketch (hand written sig) to my I////////////cloud email signature from iPad/iPhone.

This content view imports via continuity camera in Xcode 15.0. You don't seem to need ImportFromDevicesCommands() in the window group

import SwiftUI
import SwiftData
import UniformTypeIdentifiers

struct ContentView: View {
    
    @State var camImage: Image?

    var body: some View {
        Rectangle()
            .fill(.green)
            .overlay(
                camImage
                    .frame(width: 400,height: 400)
                    .clipped()
                )
            .contextMenu(menuItems: {
                Text("Menu Item 1")
                Text("Menu Item 2")
                Text("Menu Item 3")
            })
            .importsItemProviders([.image,.png,.jpeg,.rawImage], onImport: { providers in
                
                for provider in providers {
                    let _ = provider.loadDataRepresentation(for: .jpeg) { data, error in
                        guard let data else { return }
                        guard let png = NSImage(data: data) else { return }
                        
                        camImage = Image(nsImage: png)
                    }
                }
                
                return true
                
            })
            
    }

}
  • Does the importsItemProviders modifier only work with context menus? I want it as a normal button menu.

    Menu { "Import from iPhone"... }

Add a Comment