2016-10-03 4 views
1

Я хочу показать анимацию gif в UserNotification (локальное уведомление), но я могу показать изображение только в уведомлении пользователя, анимация не отображается. Я делаю это в Objective-CUserNotification ios 10

мой код // планирования уведомление

NSString *[email protected]"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]; 
[email protected][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!"); 
    } 
}]; 

// этот код в AppDelegate - (ничтожной) didReceiveNotificationRequest: (UNNotificationRequest *) запрос withContentHandler: (ничтожной (^) (UNNotificationContent * contentToDeliver)) ContentHandler {

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); 

}

+0

Вы читали документацию, может быть? – holex

+0

вам нужно предоставить изображение gif, например, NSURL * url = [[NSBundle mainBundle] URLForResource: @ "recording_animate" withExtension: @ "gif"]; @kishan – KAR

ответ

1

Вы должны добавить свой файл .gif в файл Notification Service Extension. Вы можете создать из него объект UNNotificationAttachment и передать в завершениеHandler метода func didReceiveNotificationRequest(request: UNNotificationRequest, withContentHandler contentHandler: (UNNotificationContent) -> Void) подкласса UNNotificationServiceExtension.

+0

спасибо большое :) – kishan

+0

я могу; t повышать свой ответ, поскольку у меня меньше кредитов, чем 15 извините за это – kishan

+0

Вы можете отметить это как правильный ответ. – toofani

Смежные вопросы