[英]Export an UIImage as a sticker for Messages app
I'm trying to export an UIImage as a sticker for Messages app, but I can't find any documentation about this.我正在尝试将 UIImage 导出为 Messages 应用程序的贴纸,但我找不到任何关于此的文档。
I have my project with the Sticker Pack extension enabled and see that Xcode created a new Stickers.xcassets , every image that I add there manually appears on Messages app to use as a sticker, but how can I save an image programatically there, so the user can create stickers from any image?我的项目启用了贴纸包扩展,并看到 Xcode 创建了一个新的Stickers.xcassets ,我在此处手动添加的每个图像都出现在 Messages 应用程序上以用作贴纸,但是如何以编程方式将图像保存在那里,所以用户可以从任何图像创建贴纸?
All I can find is information related to creating stickers without doing any code, just shipping an app with predefined images.我所能找到的只是与创建贴纸相关的信息,而无需编写任何代码,只需发布一个带有预定义图像的应用程序。
let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "Test")
I know how create a MSSticker from the image file, but after this I don't know how to proceed and make this newly created sticker appear on Messages app.我知道如何从图像文件创建一个 MSSticker,但在此之后我不知道如何继续并使这个新创建的贴纸出现在 Messages 应用程序上。
Stickers are loaded from stickers assets catalog .xcstickers
.贴纸从贴纸资产目录
.xcstickers
加载。 This catalog is a resource file/folder, that means this is placed inside your bundle.这个目录是一个资源文件/文件夹,这意味着它被放置在你的包中。 All files inside your bundle are not writable and they have only read permissions.
捆绑包中的所有文件都是不可写的,它们只有读取权限。 IMO what you need to do is:
IMO 你需要做的是:
You have to store your users custom images in any one of the sandboxed folders (Documents, Library and temp).您必须将用户自定义图像存储在任一沙盒文件夹(文档、库和临时文件夹)中。
Read image from this folder and create MSSticker
from it same way as you did.从此文件夹中读取图像并以与您相同的方式创建
MSSticker
。 - let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "Test")
and add. -
let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "Test")
并添加。 this sticker to array.这个贴纸阵列。
MSStickerBrowserViewController
you will load stickers from array created in previous step.MSStickerBrowserViewController
,您将从上一步创建的数组中加载贴纸。 Like this像这样
override func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {
stickers.count
}
override func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView,
stickerAt index: Int) -> MSSticker {
stickers[index]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.