我通过强制将图像保存为
png
:
export class LocalNotificationsImpl extends LocalNotificationsCommon implements LocalNotificationsApi {
...
private static guid() {
// Not the best, but will it will do. See https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
return `${ s4() }${ s4() }-${ s4() }-${ s4() }-${ s4() }-${ s4() }${ s4() }${ s4() }`;
}
private static getImageName(imageURL: string = "", extension: "png" | "jpeg" | "jpg" = "png"): [string, string] {
const name: string = imageURL.split(/[\/\.]/).slice(-2, -1)[0] || LocalNotificationsImpl.guid();
return [name, `${ name }.${ extension }`];
}
...
private static async schedulePendingNotificationsNew(pending: ScheduleOptions[]): Promise<void> {
...
const imageURL: string = options.image;
if (imageURL) {
const image: ImageSource = await imageSource.fromUrl(imageURL);
const [imageName, imageNameWithExtension] = LocalNotificationsImpl.getImageName(imageURL, "png");
const path: string = fileSystemModule.path.join(
fileSystemModule.knownFolders.temp().path,
LocalNotificationsImpl.getImageName(imageURL, "png"),
);
const saved = image.saveToFile(path, "png");
if (saved || fileSystemModule.File.exists(path)) {
try {
const attachment = UNNotificationAttachment
.attachmentWithIdentifierURLOptionsError('attachment', NSURL.fileURLWithPath(path), null);
content.attachments = NSArray.arrayWithObject<UNNotificationAttachment>(attachment);
} catch(err) {}
}
}
...
}
}
如果您感兴趣,这些更改已合并到
my fork of the plugin
还有一个
PR open in the official one
.