iosobjective-cwatchkitapple-watchwkinterfacegroup

Take a snapshot of a Group element with WatchKit & save to camera roll


I'm trying to programmatically take a snapshot of a Group element and its contents (a text label) and save it to the camera roll.

I would usually do something like this (see code snippet) for an iPhone app but with WatchKit the Group element has a different structure to a UIView.

Any help would be much appreciated. Here's my code:

    // grab reference to the area you'd like to capture
    WKInterfaceGroup *theArea = _theGroup;

    // define the size and grab a UIImage from it
    UIGraphicsBeginImageContextWithOptions(theArea.bounds.size, theArea.opaque, 0.0);
    [theArea.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // save screengrab to Camera Roll
    UIImageWriteToSavedPhotosAlbum(screengrab, nil, nil, nil);

Solution

  • Unfortunately, there are no snapshot-style methods in the current version of WatchKit, so techniques like the one you've mentioned are not available. In fact, there are very few properties that can be read from a WatchKit interface.

    The only way you'll be able to do something like this is if you render the group as an image in your WatchKit extension, then use that image to populate a WKInterfaceImage (or appropriate background image) on the Watch. Of course, this means that you have to create custom drawing code that mimics the look of the Watch controls. Depending on the complexity of your interface, this could take a lot of work.