iMessage Apps - Programatically create animated st

2020-07-08 06:49发布

问题:

Hi has anyone tried yet to programatically create a custom sticker programmatically with an animated apng file?

I've had no success but can state the following:

  1. .apng file of correct dimensions and file size (300px * 300px) and < 500kb.

  2. Can add this as a .png and it shows the first frame (not animated)

  3. Changing file name to .apng causes an error to be raised upon inserting sticker to MS Message.

  4. Have taken the approach of loading the apng into the project folder (not in Assets.xcassets) as the initialize sticker requires an NSURL which is not made availabe if apng is created as an iOS sticker.

  5. Managed to user the same sequence in .GIF. this inserted correctly as a sticker.

Code below:

MSConversation *currentConversation = [self activeConversation];

NSURL *urlForSticker2 = [[NSBundle mainBundle] URLForResource:@"elephant_apng" withExtension:@"apng"];
MSSticker *challengeSticker2 = [[MSSticker alloc] initWithContentsOfFileURL:urlForSticker2 localizedDescription:@"My Sticker Localised" error:&myError];

[currentConversation insertSticker:challengeSticker2 completionHandler:^(NSError * error) 
{

//HERE we get: error    NSError *   domain: @"com.apple.messages.stickers-error" - code: 8  0x0000600000058240


 }];

So yes - keen to be able to overcome the error shown above.

回答1:

Maybe you forget click here when you add the resource?

and your apng file's extension should be just "png" when you insert a MSSticker object.