Created
June 7, 2021 13:27
-
-
Save braandl/306640e2aa98392df5b654b2b35facad to your computer and use it in GitHub Desktop.
Fix for push-notification-ios Bug that iOS can not retrieve the initially send notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
#import <React/RCTBridge.h> | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTLinkingManager.h> | |
#import <RNCPushNotificationIOS/RCTConvert+Notification.h> | |
@implementation AppDelegate { | |
__weak UILocalNotification * initialNotificationPlaceholder; | |
__weak RCTBridge *bridge; | |
} | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
NSLog(@"App launched %@", launchOptions); | |
NSMutableDictionary * newLaunchOptions = launchOptions.mutableCopy; | |
if (newLaunchOptions == nil) { | |
newLaunchOptions = [NSMutableDictionary new]; | |
} | |
UILocalNotification * placeholder = [UILocalNotification new]; | |
initialNotificationPlaceholder = placeholder; | |
[newLaunchOptions setObject:initialNotificationPlaceholder forKey:UIApplicationLaunchOptionsLocalNotificationKey]; | |
RCTBridge * bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:newLaunchOptions]; | |
self->bridge = bridge; | |
/* Initialization of the Core EventsManager singleton. */ | |
// Define UNUserNotificationCenter | |
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; | |
center.delegate = self; | |
// Do whatever you need for RN and your App. | |
return YES; | |
} | |
/* | |
Other App Delegate interface implementations here. | |
*/ | |
- (void)userNotificationCenter:(UNUserNotificationCenter *)center | |
didReceiveNotificationResponse:(UNNotificationResponse *)response | |
withCompletionHandler:(void (^)(void))completionHandler | |
{ | |
UILocalNotification * wrapper= [[self->bridge launchOptions] objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; | |
NSDictionary * realNotification = [RCTConvert RCTFormatUNNotificationResponse:response]; | |
wrapper.alertAction = realNotification[@"alertAction"]; | |
wrapper.alertBody = realNotification[@"alertBody"]; | |
wrapper.alertLaunchImage = realNotification[@"alertLaunchImage"]; | |
wrapper.alertTitle = realNotification[@"alertTitle"]; | |
wrapper.applicationIconBadgeNumber = [realNotification[@"applicationIconBadgeNumber"] intValue]; | |
wrapper.category = realNotification[@"category"]; | |
wrapper.fireDate = realNotification[@"date"]; | |
wrapper.hasAction = realNotification[@"hasAction"]; | |
wrapper.region = realNotification[@"region"]; | |
wrapper.regionTriggersOnce = realNotification[@"regionTriggersOnce"]; | |
wrapper.repeatCalendar = realNotification[@"repeatCalendar"]; | |
wrapper.repeatInterval = [realNotification[@"repeatInterval"] intValue]; | |
wrapper.soundName = realNotification[@"soundName"]; | |
wrapper.timeZone = realNotification[@"timeZone"]; | |
wrapper.userInfo = realNotification[@"userInfo"]; | |
[RNCPushNotificationIOS didReceiveNotificationResponse:response]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment