Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library Example #7

Open
toyinswift opened this issue Dec 24, 2022 · 0 comments
Open

Library Example #7

toyinswift opened this issue Dec 24, 2022 · 0 comments

Comments

@toyinswift
Copy link

toyinswift commented Dec 24, 2022

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)
        }
        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant