Post

Replies

Boosts

Views

Activity

[PHPicker] The webp Data loaded by PHPickerViewController cannot determine the type
【Use】 open func loadDataRepresentation(forTypeIdentifier typeIdentifier: String, completionHandler: @escaping (Data?, Error?) -> Void) -> Progress if self.hasItemConformingToTypeIdentifier(UTType.webP.identifier) {             return try await self.loadDataRepresentation(forTypeIdentifier: UTType.webP.identifier) } At this point you can load webp Image。But it is impossible to judge this time webp through Data, because he is indistinguishable from jpeg。 extension Data {     var isWebP: Bool {         // Ensure the size of the data is large enough         // for us to properly check.         guard self.count >= 12 else {             return false         }         return withUnsafeBytes { bytes in             // The first 4 bytes are the ASCII letters "RIFF"             // Skipping 4 bytes for the file size, the next 4 bytes after             // that should read "WEBP"             if String(decoding: bytes[0..<4], as: UTF8.self) != "RIFF" ||                 String(decoding: bytes[8..<12], as: UTF8.self) != "WEBP" {                 return false             }             return true         }     }
0
0
588
Jun ’22
Xcode16.3 SwiftUI Preview Crash
Xcode16.3 SwiftUI Preview Library not loaded: /usr/lib/swift/libswiftWebKit.dylib Untitled.rtf
Replies
1
Boosts
1
Views
571
Activity
Apr ’25
[PHPicker] The webp Data loaded by PHPickerViewController cannot determine the type
【Use】 open func loadDataRepresentation(forTypeIdentifier typeIdentifier: String, completionHandler: @escaping (Data?, Error?) -> Void) -> Progress if self.hasItemConformingToTypeIdentifier(UTType.webP.identifier) {             return try await self.loadDataRepresentation(forTypeIdentifier: UTType.webP.identifier) } At this point you can load webp Image。But it is impossible to judge this time webp through Data, because he is indistinguishable from jpeg。 extension Data {     var isWebP: Bool {         // Ensure the size of the data is large enough         // for us to properly check.         guard self.count >= 12 else {             return false         }         return withUnsafeBytes { bytes in             // The first 4 bytes are the ASCII letters "RIFF"             // Skipping 4 bytes for the file size, the next 4 bytes after             // that should read "WEBP"             if String(decoding: bytes[0..<4], as: UTF8.self) != "RIFF" ||                 String(decoding: bytes[8..<12], as: UTF8.self) != "WEBP" {                 return false             }             return true         }     }
Replies
0
Boosts
0
Views
588
Activity
Jun ’22