Post

Replies

Boosts

Views

Activity

Live Activities is not working with custom colours from Asset Catalog
When I try to use custom colours in Live Activities, the activity in the Lock Screen is not appear at all. In the code, I use an extension to conform Color to Codable, otherwise is not compile. public typealias TimeTrackingStatus = ContentState public struct ContentState: Codable, Hashable { var elapsedTime: Int var remainingTime: Int var meetingDuration: Double var mainColor: Color } } extension Color: Codable { // Full code in the link } And here is the Live Activity view: struct TimeTrackingWidgetView: View { let context: ActivityViewContext<MeetingTimerAttributes> var body: some View { VStack { Text("Total Time: \(Int(context.state.meetingDuration)) minutes") .padding(.top, 10) .bold() HStack { VStack(alignment: .leading) { Text("Minutes Elapsed") .font(.caption) Label("\(context.state.elapsedTime.secondsToMinutes())", systemImage: "hourglass.bottomhalf.fill") } Spacer() VStack(alignment: .trailing) { Text("Minutes Remaining") .font(.caption) Label("\(context.state.remainingTime.secondsToMinutes())", systemImage: "hourglass.tophalf.fill") .labelStyle(.titleAndIcon) } } .padding(.init(top: 5, leading: 15, bottom: 10, trailing: 15)) } .background(context.state.mainColor) <---- This line } } If I use .background(context.state.mainColor) the Live activity is not appear but if I use background(.red), for example, it works just fine. The color are sRGB created in the assets catalog, like this one: Any idea?
0
0
1.3k
Nov ’22
New ShareLink with custom type is not working
Hi everyone!  I want to share audio files with the new ShareLink in SwiftUI. I've a Recording entity from Core Data, witch store the URL from the audio file and the file itself is store in the FileManger. I already make Recording to conform Transferable protocol. But in the line of the Sharelink appears an error compiler: "No exact matches in call to initializer". Here is the code: Recording entity: @nonobjc public class func fetchRequest() -> NSFetchRequest<Recording> { return NSFetchRequest<Recording>(entityName: "Recording") } @NSManaged public var date: Date @NSManaged public var id: UUID @NSManaged public var url: String @NSManaged public var title: String } extension Recording : Identifiable, Transferable { // Transferable protocol static var containerUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) public static var transferRepresentation: some TransferRepresentation { FileRepresentation(exportedContentType: .audio) { audio in SentTransferredFile(URL(string: audio.url)!) } } } View: @ObservedObject var recording: Recording var body: some View { NavigationStack { VStack(spacing: 20){ VStack { Text(recording.title) .font(.title) .bold() Text("\(recording.date, format: .dateTime)") .foregroundColor(.secondary) } } } .toolbar { ToolbarItem(placement: .navigationBarLeading) { ShareLink(item: recording) { // This line gives the error: No exact matches in call to initializer Image(systemName: "square.and.arrow.up") } } } Any idea? I have tried to simplify the code so let me know if I have forgotten something. Thanks!
4
0
2k
Sep ’22