2017-11-21 2 views
1
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에 저장된 스티커를 얻을 수 있습니다. 그러나 문서 지시문의 경로를 지정하면 스티커가 표시되지 않습니다. 사용자가 오프라인으로 볼 수 있도록 내 sqlite (이미지 이름) 및 문서 지시문의 이미지를 저장하여 api에서 imges를 다운로드합니다. 나는 해결책을 찾지 못한다. 무엇이 잘못 되었는가, 올바른 방법을 찾도록 도와주세요. 감사합니다.Swift에서 문서 디렉토리의 스티커를 표시하는 방법

 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 
+0

예. /var/mobile/Containers/Data/PluginKitPlugin/DE11FB0E-89F9-4A65-917E-B4FEB8CA5470/Documents/111111-1508763742.gif ---- 111111-1508763742.gif --- 내 이미지 이름입니다. –

+0

서버에서 gif 파일을 다운로드 한 후 이미지를 저장하는 방법은 무엇입니까? –

답변

0

시도해 볼 수 있습니까? MSSticker가 문서 경로와 이미지 이름을 추가하는 것을 잊지 URL의 path.Don't와 스티커를 만들 수 있기 때문에이 메이크업의 URL 후

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

. 이미지 경로를 얻은 후이 작업을 수행하십시오.

let pathurl = URL(fileURLWithPath: imagePath!) 

이제 스티커를 만들 수 있습니다.

MSSticker(contentsOfFileURL: pathurl, localizedDescription: "hello world") 
관련 문제