I'm creating my own iMessage Custom App and I simply want to send an iMessage with a background that swaps between 2 images, therefore creating the illusion of animation. I'm not even sure this is possible but I'm trying with the code below. This code only shows the first image when the message is received by the recipient. Any help would be appreciated.
func createImageForMessage() -> UIImage? {
let cupAnimation = UIImageView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
let imagesListArray = [UIImage(named: "boy_cup_1_1.png")!,UIImage(named: "boy_cup_1_7.png")!]
cupAnimation.animationImages = imagesListArray
cupAnimation.animationDuration = 10.0
cupAnimation.animationRepeatCount = 50
cupAnimation.startAnimating()
let cupBackground = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
cupBackground.addSubview(cupAnimation)
background.addSubview(cupBackground)
background.frame.origin = CGPoint(x: view.frame.size.width, y: view.frame.size.height)
view.addSubview(background)
UIGraphicsBeginImageContextWithOptions(background.frame.size, false, UIScreen.main.scale)
background.drawHierarchy(in: background.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
background.removeFromSuperview()
return image
}