小编rob*_*oby的帖子

iOS 通知服务扩展会从设备中删除附加文件吗?

我遇到了一个奇怪的问题。iOS 通知服务扩展将从设备中删除附件。

我使用 SDWebImage 来显示和缓存图像,并实现了通知服务扩展以在通知警报视图中显示图像。

就我而言,图像已在本地缓存。然后,我单击主页按钮,我的应用程序在后台运行,应用程序安排了一个本地通知,并将缓存的图像附加到通知内容中。

请参阅下面的代码:

1.安排本地通知

+ (void)postLocalNotificationGreaterThanOrEqualToiOS10:(LNotification)module body:(NSDictionary *)body {
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.sound = [UNNotificationSound defaultSound];
content.body = @"body";
content.userInfo = @{};

//get the image in device to attach into notification
NSError *error;
NSString* imgURL = [body valueForKey:kLocalNotification_Image];
NSString *filePath = [[SDImageCache sharedImageCache] defaultCachePathForKey:imgURL];
NSURL *url = [NSURL URLWithString:[@"file://" stringByAppendingString:filePath]];
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:@"Image" URL:url options:nil error:&error];
if (attachment) {
    content.attachments = @[attachment];
}

UNTimeIntervalNotificationTrigger* trigger = …
Run Code Online (Sandbox Code Playgroud)

apple-push-notifications ios unnotificationserviceextension

5
推荐指数
1
解决办法
1550
查看次数