How do you managed to do this: "I've been saving that by saving the file to disc and storing a relative URL to Core Data."? I'm having a lot of problems with this.
Post
Replies
Boosts
Views
Activity
Thanks for the response!
I updated the code to the initializer with the preview parameter and now the code compile but I have a problem with this unwrap URL: SentTransferredFile(URL(string: audio.url)!)
And since the url is a String, I have to use URL(string), is there any way to deal with this optional?
I was watching this session from the WWDC22, minute 9:14, and here they use another approach:
static var transferRepresentation: some TransferRepresentation {
FileRepresentation(contentType: .mpeg4Movie) {
SentTransferredFile($0.file)
} importing: { received in
let destination = try Self.copyVideoFile(source: received.file)
return Self.init(file: destination)
}
}
This makes sense but when I apply it in my own code I have problems with the line return Self.init(file: destination), since in my case I have an entity called Recording, without any variable called "File", but if I understand correctly, I must associate destination to Recording.url, is this correct?
You will need to check that the value in the url property is a genuine URL
I used nil coalescing to provide a default URL URL(fileURLWithPath: "/dev/null"), but every time I tried to use the Sharesheet, nothing happens and the debug area shows this error: [ShareSheet] cancelled request - error: The operation couldn’t be completed. Invalid argument. Sharing finished with error: Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument" at SwiftUI/SharingActivityPickerBridge.swift:266
So I think the main issue is that, for whatever reason the URL is nil and I can't understand why because in the Recoding model the url is not even optional. The only thing I can think right now is that the URL is a String instead of URL (that's why I need to use URL(string:) in the SentTransferredFile part, to convert the string into an URL) and maybe this is the problem with the optional. Any idea? Many thanks!
Hello, I know this thread is quite old, but have you been able to solve this problem? I'm in a similar situation but with audio files. Thank you.
I know this post is quite old, but have you been able to solve this problem? I'm in a similar situation. Thank you.
I'm in a very similar situation like you. Did you find any conclusions about this?