没有显示第二个通知的丰富通知图像

时间:2017-03-30 10:10:33

标签: objective-c ios10

使用UNNotificationAttachment图像同时安排2个本地通知。如果我从移动通知托盘中清除了第一个通知,那么对于没有显示附加图像的第二个丰富通知。

这是我的代码: -

- (void)scheduleNotification1 {

    UNMutableNotificationContent *notificationContent = [[UNMutableNotificationContent alloc] init];
    notificationContent.body = @"Reminder 1 Notification";
    notificationContent.categoryIdentifier = @"Reminder 1";

    notificationContent.sound = [UNNotificationSound defaultSound];
        notificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber]);
    NSString *imageURLString = [[NSBundle mainBundle] pathForResource:@"bird" ofType:@"jpeg"];
    UNNotificationAttachment *imageAttachment = [UNNotificationAttachment attachmentWithIdentifier:@"Reminder 1" URL:[NSURL fileURLWithPath:imageURLString] options:nil error:nil];
    notificationContent.attachments = @[imageAttachment];

    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10
                                                                                                    repeats:NO];
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"Reminder 1"
                                                   content:notificationContent
                                                   trigger:trigger];

    /// 3. schedule localNotification
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = (id)((AppDelegate *) [[UIApplication sharedApplication] delegate]);
    [center addNotificationRequest:request
             withCompletionHandler:^(NSError * _Nullable error) {
                 if (!error)
                 {
                     NSLog(@"Error %@",error);

                 }
                 else
                 {
                     NSLog(@"Error-- ");
                 }

             }];

    [self scheduleNotification2];

}

- (void)scheduleNotification2 {

    UNMutableNotificationContent *notificationContent = [[UNMutableNotificationContent alloc] init];
    notificationContent.body = @"Reminder 2 Notification";
    notificationContent.categoryIdentifier = @"Reminder 2";
    notificationContent.sound = [UNNotificationSound defaultSound];
    notificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber]);
    NSString *imageURLString = [[NSBundle mainBundle] pathForResource:@"bird1" ofType:@"jpeg"];
    UNNotificationAttachment *imageAttachment = [UNNotificationAttachment attachmentWithIdentifier:@"Reminder 2" URL:[NSURL fileURLWithPath:imageURLString] options:nil error:nil];
    notificationContent.attachments = @[imageAttachment];
    UNNotificationRequest *request = nil;
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:15
                                                                                                    repeats:NO];
    request = [UNNotificationRequest requestWithIdentifier:@"Reminder 2"
                                                   content:notificationContent
                                                   trigger:trigger];
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = (id)((AppDelegate *) [[UIApplication sharedApplication] delegate]);
    [center addNotificationRequest:request
             withCompletionHandler:^(NSError * _Nullable error) {
                 if (!error)
                 {
                     NSLog(@"Error %@",error);
                 }
                 else
                 {
                     NSLog(@"Error-- ");
                 }

             }];
}

=============

请让我知道为什么它没有显示第二次富通知的图像?

谢谢。

0 个答案:

没有答案