Swift UIPasteboard not copying PNG

前端 未结 4 1078
无人共我
无人共我 2021-01-03 09:28

My problem is really odd. In the simulator the .png copies to clipboard fine and I can paste the image in the Contacts app on Simulator. But when I put the app on the phone,

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 10:11

    Make sure the code runs fine in your host app (not a keyboard extension app). For example, check if the read image has the same resolution:

        //the Pasteboard is nil if full access is not granted
        let pbWrapped: UIPasteboard? = UIPasteboard.generalPasteboard()
        if let pb = pbWrapped {
            var type = UIPasteboardTypeListImage[0] as! String
            if (count(type) > 0) && (image != nil) {
                pb.setData(UIImagePNGRepresentation(image), forPasteboardType: type)
                var readDataWrapped: NSData? = pb.dataForPasteboardType(type)
                if let readData = readDataWrapped {
                    var readImage = UIImage(data: readData, scale: 2)
                    println("\(image) == \(pb.image) == \(readImage)")
                }
            }
        }
    

    If the pasteboard object is nil in your keyboard app that means you haven't provided full access to the keyboard: Copying and pasting image into a textbook in simulator

提交回复
热议问题