firebase / firebase/firebase-cpp-sdk
[Bug] Cannot use provisional notification permissions with FCM on iOS
- 主要语言
- C++
- 星标
- 326
- 派生
- 137
- 平均合并
- 3 天 9 小时
- 30 天内合并 PR
- 5
描述
### [REQUIRED] Please fill in the following fields:
* Pre-built SDK from the [website](https://firebase.google.com/download/cpp) 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](https://github.com/firebase/quickstart-cpp) ? 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);
}];
```
贡献指南
调研方向
从 Firebase C++ quickstart 中的 common_main.cc 开始,复现 issue 中描述的 iOS 12+ 临时权限流程。跟踪 Firebase Messaging 如何处理 RequestPermission、APNS 注册和 FCM token 获取。当 FCM 获取到 APNS token,并且无需 Firebase 权限提示即可获取 FCM token 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp, firebase, ios
- 领域
- mobile-dev
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100