2

I am trying to figure out way to create MSStickers with images that are hosted on the web. I can create MSStickers with local images, e.g.:

NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"image_name" 
                                                      ofType: @"png"];
NSURL *imageURL = [NSURL fileURLWithPath: urlString];
MSSticker *sticker = [[MSSticker alloc] initWithContentsOfFileURL: stickerURL
                                             localizedDescription: @"my-sticker"                                          
                                                            error: &err];

But I cannot do something like this:

NSString *imageURLString = @"https://my-cdn/my-sticker.png"; 
NSURL *imageURL = [NSURL urlWithString: urlString];
MSSticker *sticker = [[MSSticker alloc] initWithContentsOfFileURL: stickerURL
                                             localizedDescription: @"my-sticker"                                          
                                                            error: &err];
L A
  • 966
  • 11
  • 25
keisuke
  • 61
  • 3

1 Answers1

2

No, it's not possible for the moment. But you can do this, which is not that far from what you want:

  1. Download the picture from your server
  2. Store it on local directory of the device
  3. Use the URL of this local file to create your sticker
  4. Optional : If you don't need the image anymore, erase it from the directory
RomOne
  • 2,065
  • 17
  • 29
  • when you DL the remote images, do you write them all to an array of type `[URL]` in one file in the `Document` directory? – SamYoungNY Sep 15 '16 at 21:13
  • 1
    Hey! Nop, they have to be proper files with their file extension (like .png). It's like downloading an image to your computer actually. You'll find your image dowloaded from internet on your "download" folder right? Here it's the same, but the folder is in your app directory. – RomOne Sep 15 '16 at 22:58
  • Hey, thanks for getting back! OK- so should I be DL'ing, converting, and then writing the image with the following process: `String` -> `URL` -> `NSData` -> `UIImagePNGRepresentation ` -> `.writeToFile` - then finding the image in directory (as type `UIImagePNGRepresentation`) and converting it to type `MSSticker`? – SamYoungNY Sep 16 '16 at 04:34
  • 1
    Yeah you got it :) – RomOne Sep 16 '16 at 04:57