0

Alright, Im fairly new to the url locating process (I always just use explicit names) and everyone is new to MSMessageStickers. However. I need to pull in an array of image urls to use as MSStickers from a folder of images I have copied into my MessagesExtension target in my project here (it is starterPack):

enter image description here

It may the Swift 3 syntax screwing this up or something else, but I CANT find any way to just get the right url of this folder and get all the images inside of it. The following is successful in making stickers out of PNGS with specific names:

for i in (1..<2) {
                if let url = Bundle.main.url(forResource: "test\(i)", withExtension: "png") {
                    do {
                        //let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "")
                        let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "")
                        //print("SUCCESS", url)
                        stickers.append(sticker)
                    } catch {
                        print(error)
                    }
                }
        }

And I have adapted the following to Swift 3 from similar question How to get array of UIImage, from folder, in Swift? :

if let path = NSBundle.mainBundle().resourcePath {

        let imagePath = path + "/images"
        let url = NSURL(fileURLWithPath: imagePath)
        let fileManager = NSFileManager.defaultManager()

        let properties = [NSURLLocalizedNameKey,
                          NSURLCreationDateKey, NSURLLocalizedTypeDescriptionKey]

        do {
            let imageURLs = try fileManager.contentsOfDirectoryAtURL(url, includingPropertiesForKeys: properties, options:NSDirectoryEnumerationOptions.SkipsHiddenFiles)

            print("image URLs: \(imageURLs)")
            // Create image from URL
            var myImage =  UIImage(data: NSData(contentsOfURL: imageURLs[0])!)

        } catch let error1 as NSError {
            print(error1.description)
        }
    }

But because the folder is not technically in my project folder but rather in the messagesExtension folder as you can see, I think that is why it cant find it.

I need to bring in and get the url of all the images contained in my stickers folder. What am I doing wrong?

Community
  • 1
  • 1
blue
  • 7,175
  • 16
  • 81
  • 179

0 Answers0