Skip to content

Library Example #7

@toyinswift

Description

@toyinswift

Please include an example on how to use the Library to generate .watchface file from. swiftui. Thanks

This is the code that am currently using. But it says watch face sharing is not available.


        do {
            
            let localIdentity = "\(UUID().uuidString)/L0/001"
            let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
            var faceURL = paths.appendingPathComponent("\(name).watchface")
            let fullImage = UIImage(named:"owl")
            let owl = fullImage!.resized(toWidth: 384)!.pngData()!
            
            let item =  Watchface.Resources.Metadata.Item(imageURL: "owl.png", irisVideoURL: "", localIdentifier: localIdentity, originalCropH: 0, originalCropW: 0, originalCropX: 0, originalCropY: 0)
            let meta = Watchface.Resources.Metadata(imageList: [item],version: 4)
            let resources = Watchface.Resources(images: meta, files:["owl.png":owl])
            let position = PhotosWatchface.Position.top
            let utility = Watchface.Metadata.CLKComplicationTemplateUtilitarianSmallFlat()
            let facer = PhotosWatchface(device_size:6 ,position: .top, snapshot: snapshot, no_borders_snapshot: no_borders_snapshot, resources: resources)
            var watchy = Watchface(photosWatchface: facer)
            let fw = try FileWrapper(watchface: watchy)
            try fw.write(to: faceURL, originalContentsURL:nil)
            let data = try Data(contentsOf: faceURL)
            UIPasteboard.general.setData(data, forPasteboardType: "com.apple.watchface")
            
        }  catch {
            
            
            print(error.localizedDescription)
        }
        

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions