2016-10-03 15 views
1

UserNotification(ローカル通知)にgifアニメーションを表示したいが、私はユーザー通知の画像しか表示できません。アニメーションは表示されません。 (UNNotificationRequest *)リクエスト withContentHandler:(無効(無効)didReceiveNotificationRequest - 私は、Objective-CのUserNotification 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 でこのコードでこれをやっています(^)(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オブジェクトを作成し、func didReceiveNotificationRequest(request: UNNotificationRequest, withContentHandler contentHandler: (UNNotificationContent) -> Void)メソッドのcompletionHandlerをUNNotificationServiceExtensionサブクラスに渡すことができます。

+0

ありがとうたくさん:) – kishan

+0

私は、あなたが15歳未満の信用を持っているので、答えをアップアップすることはできません – kishan

+0

あなたはそれを正解とマークすることができます。 – toofani