Skip to content

RNFirebaseMessaging RCTConvert UILocalNotification category overrides PushNotificationIOS's #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahmdx opened this issue Mar 3, 2018 · 2 comments

Comments

@ahmdx
Copy link

ahmdx commented Mar 3, 2018

Issue

Scheduling local notifications using PushNotificationIOS while RNFirebaseMessaging is present does not work as expected because RNFirebaseMessaging introduces its own RCTConvert category for UILocalNotification. This category declares a class method which accesses notification data using different keys other than those in PushNotificationIOS.

RNFirebaseMessaging RCTConvert category method:

+ (UILocalNotification *)UILocalNotification:(id)json
{
    NSDictionary<NSString *, id> *details = [self NSDictionary:json];
    UILocalNotification *notification = [UILocalNotification new];
    notification.fireDate = [RCTConvert NSDate:details[@"fire_date"]] ?: [NSDate date];
    if([notification respondsToSelector:@selector(setAlertTitle:)]){
        [notification setAlertTitle:[RCTConvert NSString:details[@"title"]]];
    }
    notification.alertBody = [RCTConvert NSString:details[@"body"]];
    notification.alertAction = [RCTConvert NSString:details[@"alert_action"]];
    notification.soundName = [RCTConvert NSString:details[@"sound"]] ?: UILocalNotificationDefaultSoundName;
    notification.userInfo = details;
    notification.category = [RCTConvert NSString:details[@"click_action"]];
    notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeat_interval"]];
    notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"badge"]];
    return notification;
}

PushNotificationIOS RCTConvert category method:

+ (UILocalNotification *)UILocalNotification:(id)json
{
  NSDictionary<NSString *, id> *details = [self NSDictionary:json];
  BOOL isSilent = [RCTConvert BOOL:details[@"isSilent"]];
  UILocalNotification *notification = [UILocalNotification new];
  notification.alertTitle = [RCTConvert NSString:details[@"alertTitle"]];
  notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date];
  notification.alertBody = [RCTConvert NSString:details[@"alertBody"]];
  notification.alertAction = [RCTConvert NSString:details[@"alertAction"]];
  notification.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
  notification.category = [RCTConvert NSString:details[@"category"]];
  notification.repeatInterval = [RCTConvert NSCalendarUnit:details[@"repeatInterval"]];
  if (details[@"applicationIconBadgeNumber"]) {
    notification.applicationIconBadgeNumber = [RCTConvert NSInteger:details[@"applicationIconBadgeNumber"]];
  }
  if (!isSilent) {
    notification.soundName = [RCTConvert NSString:details[@"soundName"]] ?: UILocalNotificationDefaultSoundName;
  }
  return notification;
}

The keys accessed inside details dictionary are different in both implementations and, therefore, makes PushNotificationIOS implementation obsolete unless keys accessed by RNFirebaseMessaging are passed in JS.

For example, instead of using:

const notification = { fireDate: ..., alertBody: ... }

Use:

const notification = { fire_date: ..., body: ... }

Environment

  1. Application Target Platform: iOS
  1. Development Operating System: N/A
  1. Build Tools: N/A
  1. React Native version: 0.50.4
  1. RNFirebase Version: 3.2.0
  1. Firebase Module: Messaging
@chrisbianca
Copy link
Contributor

@ahmedabadie Thanks for flagging this - Messaging / Notifications are currently being completely rewritten as part of #595 and you'll be pleased to know that the RCTConvert function for UILocalNotification is no more.

Please follow #595 for news on release - we're getting closer!

@chrisbianca
Copy link
Contributor

Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!

Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1

If you have any comments and suggestions or want to report an issue, come find us on Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants