首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UserNotification ios 10

UserNotification ios 10
EN

Stack Overflow用户
提问于 2016-10-03 08:58:04
回答 1查看 1.8K关注 0票数 1

我想在UserNotification(本地通知)中显示一个gif动画,但是我只能在用户通知中显示一个图像,动画不能显示。我这样做是为了目标-c

我的代码//调度通知

代码语言:javascript
复制
NSString *UNExtensionID=@"animatedContentExtension";
NSError *error;
UNMutableNotificationContent *content = [[UNMutableNotificationContent    alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:@"Test   Notification:" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Hello  there!It is a multimedia notification with animation!"
                                                     arguments:nil];
content.sound = [UNNotificationSound defaultSound];

UNNotificationAttachment *attachment;
 NSURL *url =  [[NSBundle mainBundle] URLForResource:@"bike" withExtension:@"png"];

 attachment=[UNNotificationAttachment attachmentWithIdentifier:@"imageID"
                                              URL: url
                                            options:nil
                                            error:&error];
content.attachments=@[attachment];
content.categoryIdentifier=UNExtensionID;

content.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 1);
 UNTimeIntervalNotificationTrigger *trigger =    [UNTimeIntervalNotificationTrigger
                                              triggerWithTimeInterval:20.0f repeats:NO];
  UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond"
                                                                      content:content trigger:trigger];


UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
    if (!error) {
        NSLog(@"add NotificationRequest succeeded!");
    }
}];

// (void)didReceiveNotificationRequest:(UNNotificationRequest *中的// AppDelegate请求withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler{

代码语言:javascript
复制
 UNNotificationAttachment *attachment;
 NSError *error;

  UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
 NSURL *url =  [[NSBundle mainBundle] URLForResource:@"bike" withExtension:@"png"];

 attachment=[UNNotificationAttachment attachmentWithIdentifier:@"imageID"
                                                          URL:url
                                                      options:nil
                                                        error:&error];
    content=request.content.mutableCopy;
    content.attachments= @[attachment];
    `enter code here`contentHandler(content);

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-07 13:28:24

您必须将.gif文件添加到Notification Service Extension文件中。您可以从其中创建一个UNNotificationAttachment对象,并传入completionHandler of func didReceiveNotificationRequest(request: UNNotificationRequest, withContentHandler contentHandler: (UNNotificationContent) -> Void)方法的UNNotificationServiceExtension子类。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39827825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档