Skip to content

[Bug] Cannot use provisional notification permissions with FCM on iOS #1227

Open
@julien-l

Description

[REQUIRED] Please fill in the following fields:

  • Pre-built SDK from the website or open-source from this repo: built from sources
  • Firebase C++ SDK version: 10.4.0
  • Problematic Firebase Component: Cloud Messaging
  • Other Firebase Components in use: n/a
  • Platform you are using the C++ SDK on: MacOS 13.2.1 (22D68)
  • Platform you are targeting: iOS

[REQUIRED] Please describe the issue here:

FCM does not register with APNS when suppressing the permission prompt during FCM initialization.

Why suppressing the permission prompt? To use "provisional permissions" on iOS 12 in order to get permission without prompting the user.

But failing to execute ::firebase::messaging::RequestPermission() will prevent FCM to call UIApplication .registerForRemoteNotifications and we will never get an APNS token. I filled it as a bug since it is unclear that APNS registration is performed only when requesting permissions and this prevents client apps to use provisional permissions while still relying on FCM for APNS registration.

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase C++ quickstarts ? Yes with code change to adjust for provisional permissions

What's the issue repro rate? (eg 100%, 1/5 etc)
Always

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

  1. remove call to ::firebase::messaging::RequestPermission() in file common_main.cc

  2. replace with your own call to request provisional user notification permission on iOS 12+

  3. run app as usual, console will display:

    2023-03-02 [423:10411] 10.4.0 - [FirebaseMessaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '18207577403'.Be sure to re-retrieve the FCM token once the APNS device token is set.
    2023-03-02 [423:10411] 10.4.0 - [FirebaseMessaging][I-FCM002022] Declining request for FCM Token since no APNS Token specified

Relevant Code:

Code the request provisional permissions:

UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionSound
    | UNAuthorizationOptionBadge;
if (__builtin_available(iOS 12.0, *)) {
    options |= UNAuthorizationOptionProvisional;
}
UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:options
    completionHandler:^(BOOL granted, NSError * _Nullable error)
    {
        notify_app(granted);
    }];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions