我如何在Swift中显示Document Directory的贴纸


    DispatchQueue.main.async
        {
            var x : Int = 0
            for item in self.arrGifs
            {
                let gif : GIF = item as! GIF
                let gifName = URL(string: gif.gifImage)?.lastPathComponent
                // let ur
                let pathUrl = URL.urlInDocumentsDirectory(with: "(gifName!)").path
                print("image path is =====>", pathUrl)

                //RawImages.xcassets

                // if let url =  Bundle.main.url(forResource:"3", withExtension: "gif")
               //  {
                    print("url is ------>>>> ",url)
                    do
                    {
                        let sticker = try
                      //     MSSticker(contentsOfFileURL: url,localizedDescription: "")
                            MSSticker(contentsOfFileURL: URL(string:pathUrl)!,localizedDescription: "")

                        self.arrSticker.append(sticker)
                    }
                    catch
                    {
                        print(error.localizedDescription)
                    }
               //  }
            }
            self.createStickerBrowser()
    }

对于上述" MSSTICKER(contentsOffileurl:url,entimizedDescription:")"我可以获得保存在捆绑中的贴纸。但是,如果我提供文件指示的路径,则不会显示贴纸。我正在从API下载IMGE,保存我的SQLite(图像名称)和Document Directry中的图像,以便用户可以离线查看它。我没有找到解决方案。需要帮助什么错误以及如何正确地做。谢谢。

     file:///private/var/containers/Bundle/Application/F8FF754B-F012-4B75-AA2E-9FA71846E6AB/Migos%20Lingo.app/PlugIns/MigosLingo.appex/3.gif === this from Bundle and I can view as Sticker
    /var/mobile/Containers/Data/PluginKitPlugin/DE11FB0E-89F9-4A65-917E-B4FEB8CA5470/Documents/111111-1508763742.gif   ===> Document directry and I cannot view as Stickers 

您可以尝试一下。

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

之后,因为 msSticker 使用url路径创建标签。不要忘记使用文档路径附加图像名称。获得图像路径后,就这样做。

let pathurl =  URL(fileURLWithPath: imagePath!)

现在您可以创建贴纸。

MSSticker(contentsOfFileURL: pathurl, localizedDescription: "hello world")

相关内容