2

In the short period of notification service extension's

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler  

I can modify the UNMutableNotificationContent properties except the userInfo. Taking a mutuablecopy of userInfo dictionary and altering and setting it back again is not working.

guhan0
  • 666
  • 6
  • 19

2 Answers2

0

Simply do:

Swift 4:

bestAttemptContent?.userInfo.updateValue("someValue", forKey: "someKey")
gbhall
  • 13,139
  • 9
  • 37
  • 42
0

I haven't found any documentation about this. But for me it didn't work out when I tried to set my custom type as a value for a certain kvp in userInfo dictionary. Regular strings works just fine:

// works fine with an enum string raw value.
bestAttemptContent.userInfo["myEnumVariable"] = MyEnum.someCase.rawValue

// doesn't work.
// Only shows raw push, ignoring all changes done via notification extension.
bestAttemptContent.userInfo["myEnumVariable"] = MyEnum.someCase