gpt4 book ai didi

ios - 无法从iOS 10中的App组共享容器中获取扩展应用程序中的图像

转载 作者:行者123 更新时间:2023-12-01 18:43:02 25 4
gpt4 key购买 nike

在我的主机应用程序中,通过以下网址成功保存后,我正在下载自定义表情符号图像文件夹。

NSURL* shareContainerURL =   [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.company.app.PushServiceExtn"];

而且,只要用户点击表情符号图标,所有的自定义表情符号都会通过shareContainerURL在网格中的键盘位置显示,而不出现任何问题。

我创建了PushNotification服务扩展,需要在每次推送时通过从有效内容中提取表情符号名称来显示自定义表情符号图像。使用下面的代码。
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

NSDictionary* mediaAttachment = [self.bestAttemptContent.userInfo objectForKey:@"media-attachment"];
NSString* attachType = [mediaAttachment objectForKey:@"attachType"];
if ([attachType isEqualToString:@"emoji"]) {
NSString* strEmojiURL = [mediaAttachment objectForKey:@"url"];
self.bestAttemptContent.title = strEmojiURL;
NSString* emojiName = [[strEmojiURL stringByRemovingPercentEncoding] lastPathComponent];
NSString* strUnpresseedEmojiPath = [self getFullPath:@"emoji/Pressed"];
NSString* strImagePath = [NSString stringWithFormat:@"%@/%@ Pressed.png",strUnpresseedEmojiPath, emojiName];
NSURL* fileURL = [NSURL fileURLWithPath:strImagePath];
NSData *imageData = [NSData dataWithContentsOfURL:fileURL];
UIImage *image = [UIImage imageWithData:imageData];
if (image) {
NSError* error;
// CGRect rect = CGRectMake(0,0,50,50);
// @{UNNotificationAttachmentOptionsThumbnailClippingRectKey:(__bridge NSDictionary*)CGRectCreateDictionaryRepresentation(rect)} option dict;
UNNotificationAttachment * attachement = [UNNotificationAttachment attachmentWithIdentifier:strImagePath.lastPathComponent URL:fileURL options:nil error:&error];

if (error == nil) {
self.bestAttemptContent.attachments = @[attachement];
}
}
}


self.contentHandler(self.bestAttemptContent);
}
- (NSString *)getFullPath:(NSString *)file {

NSURL* shareContainerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.company.app.PushServiceExtn"];
return [shareContainerURL.path stringByAppendingPathComponent: file];

}

我总是得到有效的url,但是第二次我得到的图像为nil,但是第一次获得每个有效的图像。无法找到根本原因。任何帮助,将不胜感激。

以下是每个图像第二次发生的错误。
2016-10-27 17:34:59.081026 pushNotificationServiceExtension[651:34632] Attachement Error = Error Domain=UNErrorDomain Code=100 "Invalid attachment file URL" UserInfo={NSLocalizedDescription=Invalid attachment file URL}

另外,请让我知道如何查看App Group共享容器,找不到找到其中包含的文件的方法。

* Update = *在推送通知中显示后,文件将被删除。

最佳答案

来自苹果公司的消息:“UNNotificationAttachment验证后,附件文件将移入附件数据存储区,以便可以通过适当的过程进行访问。位于应用包中的附件将被复制而不是移动。”

因此,我将表情符号图像复制到重复的URL,并将其分配给UNNotificationAttachment。

if (imageFileURL) {

NSURL* duplicateImageURL = [self getFullPath:@"EmojiAttachment"];
if (![fileManager fileExistsAtPath:duplicateImageURL.path]) {
[fileManager createDirectoryAtPath:duplicateImageURL.path withIntermediateDirectories:NO attributes:nil error:&error];
}
emojiName = [NSString stringWithFormat:@"%@ Unpressed.png", emojiName];
duplicateImageURL = [duplicateImageURL URLByAppendingPathComponent:emojiName];
[[NSFileManager defaultManager]copyItemAtURL:imageFileURL toURL:duplicateImageURL error:&error];
UNNotificationAttachment * attachement = [UNNotificationAttachment attachmentWithIdentifier:emojiName URL:[duplicateImageURL filePathURL] options:nil error:&error];

if (error == nil) {
self.bestAttemptContent.attachments = @[attachement];

}
else{
NSLog(@"Attachement Error = %@",error);
}
}

关于ios - 无法从iOS 10中的App组共享容器中获取扩展应用程序中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com