我在 react-native 中实现了一个通过 Firebase 发送推送通知的应用程序。大多数情况下,它运行良好,但有时,设备(主要是 iOS 13 设备)未收到推送通知。
对于正确接收我的推送通知的设备,每次(前台和后台)都会触发onNotification。
对于未收到我的推送通知的设备,会触发onMessage(仅在前台)。
包.json
"react-native-firebase": "^5.6.0"
Run Code Online (Sandbox Code Playgroud)
播客文件
pod 'Firebase/Core', '~> 6.19.0'
pod 'Firebase/Functions', '~> 6.19.0'
pod 'Firebase/Messaging', '~> 6.19.0'
pod 'Firebase/Auth', '~> 6.19.0'
Run Code Online (Sandbox Code Playgroud)
为了测试我的推送通知,我通过 POSTMAN 发送它,使用 firebase API 和当前有效负载:
{
"to" : "my_FCM_token",
"priority" : "high",
"notification" : {
"body" : "Body TEST",
"title": "TEST Notification",
"vibrate": 1,
"sound": 1
},
"data" : {
"key" : "value"
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,它总是让我成功
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// FIREBASE …
Run Code Online (Sandbox Code Playgroud) push-notification ios firebase react-native react-native-firebase
我对 SwiftUI 非常熟悉,为了使我的代码更具可读性,我通常将视图分解为更小的视图。
假设我有一个 viewModel,从嵌套视图调用 viewModel 方法的最佳方法是什么?现在我将 ViewModel 作为每个嵌套视图的参数传递,但我发现它不是非常优化和干净......
有没有办法通知 MyMainView HeaderSubview 的按钮被点击?例如,我可以使用组合吗?
视图模型
class MyViewModel {
func fetchSomeData() {
print("Fetching Some Data")
}
}
Run Code Online (Sandbox Code Playgroud)
主视图
struct MyMainView: View {
var myViewModel = MyViewModel()
var body: some View {
HeaderView(viewModel: myViewModel)
}
}
struct HeaderView: View {
var viewModel: MyViewModel
var body: some View {
HeaderSubview(viewModel: viewModel)
}
}
struct HeaderSubview: View {
var viewModel: MyViewModel
var body: some View {
Button("Search") {
// I want to call my View …
Run Code Online (Sandbox Code Playgroud)