There are multiple examples how you should set up your project to add rich notifications which use 'media attachments' technology to show images. I've read most of them but something I missed, because my project does not display any rich notifications with this payload (tested with APNS-Tool and Boodle):
{
"aps":{
"alert":{
"title": "Rich test",
"body": "Dancing Banana"
},
"mutable-content": 1
}
}
The notification is visible, but on 3D Touch, there are no additional infos displayed (like the image or the modified title). The notification extension breakpoints and NSLog
messages are also not working.
Here is my demo project: https://github.com/gklka/RichTest
What I've done:
- Created a new project
- implemented iOS-style authorization:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) { if (granted) { NSLog(@"Granted"); [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { NSLog(@"Error registering: %@", error); } }];
- added debug to AppDelegate:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"Token: %@", deviceToken); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Error: %@", error); }
- Added a new target to the project: Notification Service Extension:
Added
banana.gif
to the projectAdded code to add banana attachment into
NotificationService.m
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title]; // Add image attachment NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"banana" withExtension:@"gif"]; NSError *error; UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:@"banana" URL:fileURL options:nil error:&error]; self.bestAttemptContent.attachments = @[attachment];
What did I miss?
Additional info: The same thing works when I use local notifications instead of remote notifications.