【问题标题】:How can I show Stickers from Document directory in Swift如何在 Swift 中显示 Document 目录中的贴纸
【发布时间】:2018-05-04 12:12:06
【问题描述】:
    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,localizedDescription: "")” 我可以得到保存在Bundle中的贴纸。但是如果我给出文件目录的路径,则不显示任何贴纸。 我正在从 api 下载图像,将我的 sqlite(图像名称)和图像保存在文档目录中,以便用户可以离线查看它。我找不到解决方案。需要帮助什么是错的以及如何正确地做。 谢谢。

     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 

【问题讨论】:

  • 是的。 /var/mobile/Containers/Data/PluginKitPlugin/DE11FB0E-89F9-4A65-917E-B4FEB8CA5470/Documents/111111-1508763742.gif ----111111-1508763742.gif--- 是我的图像名称。
  • 从服务器下载 gif 文件后如何保存图像?

标签: ios swift imessage msstickerview mssticker


【解决方案1】:

你能试试这个吗?

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

在此之后制作 url,因为 MSSticker 使用 url 路径创建贴纸。不要忘记将您的图像名称附加到文档路径。获取图像路径后,只需执行此操作。

let pathurl =  URL(fileURLWithPath: imagePath!)

现在您可以创建贴纸了。

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

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2017-11-15
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    相关资源
    最近更新 更多