1

I am using Xcode 15 beta 5 with iOS 17 beta 4 SDK. By building with the iOS 17 SDK my app got all the new inks which work great. Saving/encoding the PKDrawing to Data also works fine. However if I want to load the same PKDrawing again, on the same simulator or device (i.e., same iOS version) it fails with "Apple Drawing Format is from a future version that is too new.".

From my understanding, reading https://developer.apple.com/documentation/pencilkit/supporting_backward_compatibility_for_ink_types?changes=_2 this is the expected behaviour when trying to load such a PKDrawing on an older iOS version which doesn't support the new ink types.

Here is a short example, which prints the error:

func testPencilKit() {
    var drawing = PKDrawing()
    let strokePoints = [
        PKStrokePoint(location: CGPoint(x: 0, y: 0), timeOffset: 0, size: CGSize(width: 3.0, height: 3.0), opacity: 2, force: 1, azimuth: 1, altitude: 1)
    ]
    let strokePath = PKStrokePath(controlPoints: strokePoints, creationDate: Date())
    
    drawing.strokes.append(PKStroke(ink: .init(.watercolor), path: strokePath))
    
    do {
        let data = drawing.dataRepresentation()
        let drawing2 = try PKDrawing(data: data)
        print("success")
    } catch {
        print(error)
    }
}

Saving & loading a PKDrawing which does not use any of the new ink types works fine.

mbuchetics
  • 1,370
  • 1
  • 17
  • 34
  • 1
    I found your example very useful. In your `do { ... } catch { ... }` block, if you save the strokes (like `let strokes = drawing.strokes`) and then recreate the drawing from those strokes (like `let drawing2 = try PKDrawing(strokes: strokes)`), it works, even with the new ink types. I'm pretty sure this issue is a bug with iOS 17 beta 4's `PKDrawing(data:)` initializer. I'm filing a feedback about it – if you have the time, you should too :) – bfox Aug 02 '23 at 20:07
  • FYI my Apple feedback ID: FB12836594 – bfox Aug 02 '23 at 22:37

1 Answers1

0

This behavior was fixed in iOS 17 beta 5 (deployed from Xcode 15 beta 6). The sample code provided in the original question:

func testPencilKit() {
    var drawing = PKDrawing()
    let strokePoints = [
        PKStrokePoint(
             location: CGPoint(x: 0, y: 0),
             timeOffset: 0, 
             size: CGSize(width: 3.0, height: 3.0), 
             opacity: 2, 
             force: 1, 
             azimuth: 1, 
             altitude: 1
        )
    ]
    let strokePath = PKStrokePath(
        controlPoints: strokePoints, 
        creationDate: Date()
    )
    
    drawing.strokes.append(PKStroke(ink: .init(.watercolor), path: strokePath))
    
    do {
        let data = drawing.dataRepresentation()
        let drawing2 = try PKDrawing(data: data)
        print("success")
    } catch {
        print(error)
    }
}

...now correctly instantiates a new drawing (drawing2) without throwing any error as long as the ink types in the drawing data are available on the device.

bfox
  • 274
  • 2
  • 13