Skip to content
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

PushNotificationIOS.checkPermissions() does not return partial permissions for "alert" #25980

Closed
sorinns opened this issue Aug 7, 2019 · 4 comments
Labels
API: Alert API: PushNotificationIOS Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@sorinns
Copy link

sorinns commented Aug 7, 2019

Description

PushNotificationIOS.checkPermissions() returns "alert: false"
even when iOS notifications alerts are partially enabled

There are three options under notifications->alerts in iOS settings

  1. "Lock Screen"
  2. "Notification Center"
  3. "Banners"

.checkPermissions() returns "alert: true" or "alert: false" only based on the status of 3.

  1. and 2. are ignored and returns "alert: false" no matter what if 3. is unchecked

React Native version: 0.59.1

Steps To Reproduce

  1. call PushNotificationIOS.checkPermissions() in your code
  2. go to iOS settings and uncheck "Alert" -> "Banners" but leave "Lock Screen" and/or "Notification Center" checked

Expected Behavior

PushNotificationIOS.checkPermissions()
v1.
return more infos, for example an object like
{
alertLockScreen: bool,
alertNotificationCenter: bool,
alertBanners: bool,
sound: bool,
badge: bool,
}

v2.
just return one bool value which is true if any of the above are true

@sorinns
Copy link
Author

sorinns commented Aug 8, 2019

After some more research i did the following modifications to RTCPushNotificationManager.m in the PushNotificationIOS libray in order to also get the authorization status.

Not sure if this is the right way to do it though.

modified this

RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
{
  if (RCTRunningInAppExtension()) {
    callback(@[@{@"alert": @NO, @"badge": @NO, @"sound": @NO}]);
    return;
  }

  NSUInteger types = [RCTSharedApplication() currentUserNotificationSettings].types;
  
  callback(@[@{
    @"alert": @((types & UIUserNotificationTypeAlert) > 0),
    @"badge": @((types & UIUserNotificationTypeBadge) > 0),
    @"sound": @((types & UIUserNotificationTypeSound) > 0),
  }]);
}

with this

RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
{
  if (RCTRunningInAppExtension()) {
    callback(@[@{@"status": @NO,@"alert": @NO, @"badge": @NO, @"sound": @NO}]);
    return;
  }

  NSUInteger types = [RCTSharedApplication() currentUserNotificationSettings].types;
  
  __block bool status = YES;
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
    if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
      status = NO;
    } else {
      status = YES;
    }
    callback(@[@{
      @"status": @((status)),
      @"alert": @((types & UIUserNotificationTypeAlert) > 0),
      @"badge": @((types & UIUserNotificationTypeBadge) > 0),
      @"sound": @((types & UIUserNotificationTypeSound) > 0),
    }]);
  }];
}

@dulmandakh
Copy link
Contributor

Please create a PR to with the fix

@stale
Copy link

stale bot commented Nov 7, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 7, 2019
@stale
Copy link

stale bot commented Nov 14, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 14, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API: Alert API: PushNotificationIOS Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants